Creating Insert Statements for SQL Server

Ran across an interesting approach to generating insert statements for SQL Server 2005 (and other variants).  If uses a less well known function called master.dbo.fn_varbintohexstr. The approach that was taken was to use the fn_varbintohexstr function to encode the data so you did not need to use cursors or any fancy parsing to handle unicode and quotes in the generated … Read More

Calculating Age in T-SQL

Here’s a decent article on calculating the age of a person (or anything else) written by Lynn Pettis.  Discusses some pitfalls with leap years.

Using and Managing SQL Server Aliases

I know that not many people I have met in my SQL Server experience have used SQL Aliases.  In many ways it is one of the most useful features of SQL Server.   Roman Rehak wrote a great article about SQL Server Aliases.  You have to be registered to see the full article, but some of the highlights are discussed below. … Read More

Resetting the IDENTITY counter in SQL Server T-SQL

You’ve been there before.  You are busily testing your import routines and running up the Identity column in your main import table.  Before you know it the value is in the multi-millions and you just want to reset it back to 1.  The way to accomplish this is to use the DBCC CHECKIDENT command. For example: DBCC CHECKIDENT (SalesForce, reseed, … Read More