06 August 2012

Weekly Dynamic: Line Numbers in SQL Server

Many of you know just enough SQL to get by. By definition that involves some trial and error to get things right. Inevitably one of your Select statements will fail and SQL will give you some hints about what's wrong including a line number.

But how do figure out what line is what? Do line numbers include spaces? There is a line number listed in the bottom right but even that is a pain to use.

In SQL Server Management Studio you can turn on line numbers with Tools | Options, expand Text Editor, Expand Transact-SQL, select General and check Line Numbers under Display.