How to post a T-SQL question on a public forum

If you want to have faster turnaround on your forum questions, you will need to provide enough information to the forum users in order to answer your question. In particular, talking about T-SQL questions, there are three things that your question must include: Table scripts Sample data Expected output   Table Script and Sample data Please make sure that anyone trying to answer your question can quickly work on the same data set you’re working on, or, at least the problematic part of it. [Read More]

SQL Server and Custom Date Formats

Today SQL Server Central is featuring my article Dealing with custom date formats in T-SQL. There’s a lot of code on that page and I thought that making it available for download would make it easier to play with. You can download the code from this page or from the Code Repository. CustomDateFormat.cs formatDate_Islands_iTVF.sql formatDate_Recursive_iTVF.sql formatDate_scalarUDF.sql parseDate_Islands_iTVF.sql I was also asked to include a performance chart for the different methods included in the article. [Read More]
SQL 

Concatenating multiple columns across rows

Today I ran into an interesting question on the forums at SQLServerCentral and I decided to share the solution I provided, because it was fun to code and, hopefully, useful for some of you. Many experienced T-SQL coders make use of FOR XML PATH(‘’) to build concatenated strings from multiple rows. It’s a nice technique and pretty simple to use. For instance, if you want to create a list of databases in a single concatenated string, you can run this statement: [Read More]

Exceptional DBA Awards 2011

Time has come for the annual Exceptional DBA Awards contest, sponsored by Red Gate and judged by four really exceptional DBAs: Steve Jones (blog|twitter) Rodney Landrum (blog|twitter) Brad McGehee (blog|twitter) Brent Ozar (blog|twitter) The judges picked their finalists and it would really be hard to choose the winner if I didn’t happen to know one of them. I won’t talk around it: please vote for Jeff Moden! I don’t know the other three finalists and I am sure that they really are very good DBAs, probably exceptional DBAs, otherwise they would not have made it to the final showdown. [Read More]

Table-level CHECK constraints

EDITED 2011-08-05: This post is NOT about the "correct" way to implement table-level check constraints. If that is what you're looking for, see this post instead. Today on SQL Server Central I stumbled upon an apparently simple question on CHECK constraints. The question can be found here. The OP wanted to know how to implement a CHECK constraint based on data from another table. In particular, he wanted to prohibit modifications to records in a detail table based on a datetime column on the master table. [Read More]

My stored procedure code template

Do you use code templates in SSMS? I am sure that at least once you happened to click “New stored procedure” in the object explorer context menu. The default template for this action is a bit disappointing and the only valuable line is “SET NOCOUNT ON”. The rest of the code has to be heavily rewritten or deleted. Even if you use the handy keyboard shortcut for “Specify values for template parameters” (CTRL+SHIFT+M), you end up entering a lot of useless values. [Read More]

Setting up linked servers with an out-of-process OLEDB provider

A new article on SQLServerCentral today: Setting up linked servers with an out-of-process OLEDB provider. I had to struggle to find the appropriate security settings to make a commercial OLEDB provider work with out-of-process load and I want to share the results of my research with you. It took 50 hours of Microsoft paid support to partially solve the issue and a huge time spent on Google and MSDN to find a complete resolution. [Read More]