My SQL Server Blog
Informative posts on SQL Server Technology
My SQL Server Blog

Passing a temp table to a stored procedure

With SQL 2008, table variables can now be passed into stored procedures. Temp tables can also be passed into stored procedures from other stored procedures and triggers. This is true in 2008 and earlier versions like SQL 2005 and 2000. This allows for cleaner code as many lined stored procedures can now be broken up into multiple sub-procedures. << MORE >>

Extending TSQL ROW_NUMBER to Find MAX Rows or Row Deltas

Some common queries in a database involve grabbing the last value entered into a table for a set of items or comparing a row to its previous row. In the past this involved nasty sub queries one to find the max date and then use that value in outer query. This did not provide the cleanest of code or the best performance. Using the ROW_NUMBER function allows us to simplfy the code and improve performance.<< MORE >>

Searching All Fields in a Database for a Text String

The other day a person in my QA department came to me with a request for a script that searches all fields in a database for a text string. They were unsure where a configuration value was being stored on the system. While you could use SQL Profiler to find this information, I thought writing the script would be fun. << MORE >>

RAISERROR Percent % Sign usage

Have you ever wondered how to build a string with values for an error message? One would think that RASIERROR could simply take a string that was concatenated together with variables. Something like RAISERROR ('My Error' + @myErrorString, 16,1)<< MORE >>

Changing Export Options for Reporting Services

Have you ever wanted to change the export options for Reporting Services? Have you seen issues with report page headers being exported to Excel as non headers? Other times displaying all export options on the web is not the best idea. An end user trying to figure out what a TIF is can be a more user support time then is desired. In other cases the export might need to be renamed, instead of TIF call it Image. << MORE >>

SSRS Fit to Table to Page

Have you ever noticed that if a Total or Sub-Total line floats until to the last page by itself? Worse, table headers do not copy over when only a Sub-Total or Total is all by itself on the last page. To remedy this situation there is a table option that can be set called Fit to Page. << MORE >>

TSQL ROW_NUMBER Function

A great new feature of SQL Server 2005 is the ROW_NUMBER function. In previous versions of SQL to get a numbered row would pretty much require moving the data into a temp table with an identity column, placing an identity column on the original table, or looping through data with a cursor. SQL Server 2005 makes adding a row number to a query a very simple task with the ROW_NUMBER function.<< MORE >>

Subreports within table/matrix cells are ignored

Unfortunately, subreports within a table or matrix cannot be exported to Excel. I am not sure why MS did not allow this with Reporting Services. << MORE >>

SSRS Query Data in Header or Footer Not Exporting to Excel

One issue that I have noticed with SSRS is that headers and footers do not contain query data that is derived from a hidden text field. << MORE >>

DELETE Top TSQL Statement

A new addition to the DELETE command in SQL Server 2005 is the TOP statement. The DELETE TOP does the same thing as a SELECT TOP WHERE only the TOP number of rows are deleted. << MORE >>