T-SQL tip: log error details in catch

0 Comments

If you want to log detailed information on an error in a catch block, you can use the following code:   BEGIN CATCH declare @Message varchar(2048) = '<< Your custom error text here. >>' +

Printing table contents for debugging purposes in T-SQL

0 Comments

Sometimes you just want to add a print statement in a stored procedure to output the contents of a table. Then you can use the "FOR XML" statement in T-SQL: declare @Data_as_xml xml set @Data_as_xml

How to left pad a string in T-SQL (SQL Server 2012)

0 Comments

If you want to left pad a string in T-SQL in Microsoft SQL Server 2012, you can use the format function: To get the current hour padded with, zeros use: declare @CurrentDateTime datetime = '2013-04-03