April 4, 2006 at 1:53 pm
SELECT @t will give you a result.
SELECT * FROM @t is treating @t as a Table Variable...
I wasn't born stupid - I had to study.
April 4, 2006 at 1:57 pm
@t contains table name ('Admit')
April 4, 2006 at 2:02 pm
Is this what you want?
DECLARE @t TABLE( Field1 varchar(10))
INSERT INTO @t VALUES( 'Admit')
SELECT * FROM @t
I wasn't born stupid - I had to study.
April 4, 2006 at 2:03 pm
You can do:
use pubs
go
declare @t varchar(8)
set @t='authors'
exec ('select * from '+@t+'')
or
use pubs
go
declare @t varchar(8), @cmd nvarchar(100)
set @t='authors'
set @cmd = N'select * from '+@t+''
exec sp_executesql @cmd
Doing the way that you are trying to do, you cannot select from a variable unless it is a table variable.
April 4, 2006 at 2:05 pm
"you cannot select from a variable unless it is a table variable"
That's what I wanted to hear, thnx.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply