Archive for February, 2009

Ordinal Numbers in T-SQL

February 27th, 2009

I wanted to write a query that took numbers and turned them into ordinal numbers – re: 1 = 1st, 2 = 2nd, 3 = 3rd, etc.
I took this code from Chip Pearson’s web site. His posting was about ordinal numbers in Excel. I converted the code to a T-SQL function, and I can now [...]

Using “Execute As” to Test a Stored Procedure as a Different User

February 19th, 2009

In an earlier blog post, I wrote about how to use “Execute As” in a stored procedure to access a separate database. When you include “Execute As” in a stored procedure, you can pull data from a separate database without giving your users direct permissions on that database.
Another way I really like to use “Execute [...]

Simple way to renumber records in SQL Server

February 17th, 2009

Recently I needed to renumber a column in a database.  Specifically, I needed to be able to take a Report Number series that started with 1 (1, 2, 3, 4) and change the start number and renumber all subsequent Report Numbers (e.g, change above to 14, 15, 16, 17).
I thought I’d probably be able to [...]