SQL Server Nation
For all of your SQL Server needs.

Browse by Tags

  • Pivot Rolling Periods : Dynamic, But Not!

    In the Article, Pivot Rolling Periods Without Using Dynamic T-SQL ( experts-exchange.com/viewArticle.jsp?aid=654 ), I explored the pivot of moving date based reports without the use of dynamic T-SQL, but still allow for re-use month after month without re-writing of code. Here is another introductory tidbit to SQL Server 2005's PIVOT ( technet.microsoft.com/en-us/library/ms177410.aspx ). We will embrace the limitations of the PIVOT keyword requiring hard coded values / column names, but still...
  • Concatenating Results through SELECT statements

    In this SQL tip I am going to show you a neat little trick which involves using a simple SELECT statement to concatenate row values into a single variable value. First, I'll create a temp table named #Results for which I'll store FirstName and LastName data. IF OBJECT_ID('tempdb..#Results') IS NOT NULL DROP TABLE #Results CREATE TABLE #Results ( FirstName varchar(25), LastName varchar(25) ) GO This script adds some names to the temp table I just created. INSERT INTO #Results(FirstName...
  • Nested Common Table Expressions

    If you've looked up a Common Table Expressions in Books Online, you might have noticed that Microsoft says that you cannot have nested CTEs (meaning, you can't define a CTE in the definition of another CTE. Although this is technically true, you can still accomplish the same functionality in a different manner. Here is an example of a simple CTE using the AdventureWorks database that will return a list of orders. USE AdventureWorks ;WITH CTE_Orders (OrderID, OrderDate) AS ( SELECT PurchaseOrderID...
Copyright SQL Server Nation 2010
Powered by Community Server (Non-Commercial Edition), by Telligent Systems