Need to edge out the competition for your dream job? Train for certifications today.
-- Create a table Variable
DECLARE @myTable TABLE (
-- add some records to @myTable
Insert into @myTable (FirstName,Lastname) values ('John','Smith')
Insert into @myTable (FirstName,Lastname) values ('Jane','Doe')
Insert into @myTable (FirstName,Lastname) values ('Homer','Simpson')
-- Query Table Variable
Select * from @myTable
Open in new window
SELECT col1,col2 FROM table1
SELECT col1,col2 FROM table2
Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.
IF @YEAR ='2013'
SELECT col1,col2 FROM xx_2013
IF @YEAR ='2014'
SELECT col1,col2 FROM xx_2014
DECLARE @sql2 as nvarchar(max)
declare @tblName as varchar(50)
Select @sql2 ='select 1 from ' + @tblName
EXECUTE sp_executesql @sql2
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.