Home
Manage Your Code
Snippet: SQL Temp Table Variable (SQL)
Title: SQL Temp Table Variable Language: SQL
Description: SQL Temp Table Variable. Example shows how to insert list of database names into a temp table. Views: 559
Author: David Speight Date Added: 10/27/2011
Copy Code  
DECLARE @TVar TABLE (DBName VARCHAR(50) NOT NULL)

INSERT INTO @TVar (DBName) 
SELECT dbo.sysdatabases.name AS DBname
FROM dbo.sysaltfiles INNER JOIN dbo.sysdatabases ON 
            dbo.sysaltfiles.dbid = dbo.sysdatabases.dbid 
WHERE dbo.sysdatabases.name 
            NOT IN ( 
					'Northwind', 
					'pubs', 
					'tempdb', 
					'master', 
					'model', 
					'msdb',
					'ReportServerTempDB',
					'GTTemp',
					'RMinder'
					)
	AND dbo.sysaltfiles.name NOT LIKE '%log'
	AND dbo.sysaltfiles.name NOT LIKE '%Restore'
Usage
SQL Temp Table Variable
Notes
SQL Temp Table Variable