Tag Archives: table variable

What if you want to PIVOT against a text column?

If you’ve ever worked with or researched SQL Server’s PIVOT function, you probably noticed most of the samples pivot against an id column.  Typically an int column like EmployeeID, or StoreID.  That’s fine and dandy, but what happens when you … Continue reading

Posted in database, microsoft, SQL, tips and tricks, tsql | Tagged , , , , , , , | 2 Comments

Incorrect syntax near the keyword ‘table’ in TSQL

Ran into something little that I know I’m going to forget if I don’t write down. It appears that when using a TABLE variable in tsql ( SQL Server 2005 ), you must DECLARE that variable on it’s own line, … Continue reading

Posted in database, microsoft, SQL, tsql | Tagged , , , , , | 4 Comments

What happens in EXEC, stays in EXEC. Lifespan of a MSSQL table variable

One of my all time favorite features of MSSQL 2005+ is being able to create table variables on the fly from SELECT statements. This isn’t a lesson in what table variables are, but here is an easy sample in case … Continue reading

Posted in database, development, tsql | Tagged , , , , , , , , | 1 Comment

Select random value from a range of values

Earlier I blogged about creating random numbers using tsql functions.  Here are two techniques for selecting a random value from a pre-defined range of values in a tsql script.  The first technique uses a table variable ( MSSQL 2000 + … Continue reading

Posted in database, development, microsoft, tips and tricks, tsql | Tagged , , , , , , , , | 1 Comment