Posts

String_Split function for Pre-2016 SQL Server Databases

SQL Server 2016 has (finally) a built-in string split function: STRING_SPLIT ( string , separator ) That is great, however, if you are using an earlier version, many people end up writing something that loops through the string and wherever the separator shows up, the substring is copied to a table, which is returned later. Here's an alternative... replace the separator with XML element tags and then use the built-in XML functionality to return the delimited elements. In theory, this may be slower than a tight string loop, but in practice, the XML libraries are extremely efficient, and the REPLACE function is also highly optimized. It certainly takes less code than the other approach.

Database Projects, SQL Unit Tests, and TeamCity

Image
Continuous Integration  is a really good idea, especially when you are working with a team of developers. There are lots of tools out there that can help your team build better quality into your application. TeamCity by JetBrains is one such tool that has been around for awhile; specifically, it is the one that my company uses. Visual Studio has Database Projects   SQL Server Data Tools  to address some of the inconsistencies that developers face when using a database as a storage layer; Things like version control and consistent deployment. It also includes SQL unit tests , which fills a huge gap if any  of your logic is in the database. Many organizations moved away from logic in the database years ago because it was tricky (at best) to verify logic on the data tier, of course, they were also making changes directly to the database itself... but I digress. If you are using SQL Server Data Tools, and run your unit tests locally, it is a joy to behold. Your data...

Technical KnockOut

The other day I was working on a little demonstration of using OWIN to serve local files, use dependency injection, and server Web API in a modern SPA (Single Page Application). Almost as an afterthought, I decided to use KnockoutJS and jQuery from a minimal HTML page. This was overheard by colleagues, and a firestorm erupted... "You should have used AngularJS instead; It would take less lines of code." So I pulled down AngularJS and changed my demo to placate the angry threats wishes of the religious zealots thoughtful developers at my desk. For the record, this is the code I wrote using KnockoutJS and jQuery: and here is the AngularJS version: Trying to provide equally readable formatting, the Knockout solution takes one less line of code even though you are loading two JavaScript libraries. The only fair way to count lines is to count semicolons. Both have three. That's a tie. What about the size of the libraries being loaded. Well, Angular includes...

Not everyone needs to be a software developer...

...but everyone should learn to code. I have friends who are pharmacists, lawyers, police, firemen, military, mechanics, and musicians who also write code to help them out in their jobs. Software is a tool, a versatile and powerful tool, that can be applied to any occupation or industry. Learning to code is a 21st century skill that should be required in every middle school and high school in the country. I'm not alone in this belief. There are lots and lots and lots of organizations dedicated to helping people learn to code. Even the Prime Minister of Singapore posted a Sudoku Solver that he wrote while an electrical engineering student as encouragement and an example to the world that we need more people who can code. I think that code may have been more approachable when I was learning. The video games we had were blocky and you could understand how they could worked with a minimal amount of instruction or none at all; how many versions of breakout and lunar lander mu...

Determine the column types returned from a Stored Procedure

Say you have a stored procedure that does something like this: SELECT A.id, 10.0 * A.number / B.number AS Computed FROM Table1 A JOIN Table2 B on A.id = B.id What is the resulting type of the "Computed" column? Decimal? Float? The following SQL 2012 will tell you the data types of the columns from the first returned data set of a stored procedure: SELECT name, system_type_name FROM sys.dm_exec_describe_first_result_set_for_object (OBJECT_ID('myNamespace.mySPROC') NULL ); This will give a nice table that contains the column name and system data type name system_type_name --------------------- ---------------------- Id bigint Computed float

Getting Git Code Management

I am now the code manager for the public repository of a project that takes pull requests from several active forks and has tagged releases. The problem is, that I've not found any single resource that covers advanced code management using Git. My local repository has multiple upstream sources that I synchronize. All are hosted at github.com. This post is going to be a collection of little Git recipes. Many of them are collected from somewhere else, but others are more specific to the code management processes Configure git for certificate-based credentials for multiple logins Generate certificate I was able to get this working by following the instructions  here . However, I also needed to add some commands to my "~/.basrc" file to provide my SSH credentials to the git/bash shell window. Each ssh-add command adds one certificate to the identity store. #! /bin/bash eval `ssh-agent -s` ssh-add ~/.ssh/github_rsa ssh-add ~/.ssh/github_admin_rsa Make the local co...

MSSQL Statistical Z-Score

Computing the z-score of individual values in SQL Server is not a built in function (although average and standard deviation are). The z-score tells us how far off from the average value the individual values are. The following function computes the z-score: for a table named [data] having an [objectId] and [score] fields. SELECT [D].[objectId], [D].[score], [E].[avg_score], [E].[stdev_score], ([D].[score] - [E].[avg_score]) / [E].[stdev_score] as zvalue FROM [data] D CROSS JOIN (SELECT Avg(CAST([score] as float)) as [avg_score], StDevP([score]) as [stdev_score] FROM [data] ) E ;