Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
jeff06
Posting Yak Master
166 Posts |
Posted - 2007-11-20 : 09:55:52
|
DECLARE @TSQL varchar(8000), @VAR char(2) SELECT @TSQL = 'declare @h table (id int) ' EXEC (@TSQL)select *from @h This code give me error:Must declare the variable '@h'.Why?thanks |
|
Van
Constraint Violating Yak Guru
462 Posts |
Posted - 2007-11-20 : 10:20:10
|
Because you are selecting from @h outside of your EXEC command. It can't see @h.DECLARE @TSQL varchar(8000), @VAR char(2) SELECT @TSQL = 'declare @h table (id int) select *from @h' EXEC (@TSQL) |
 |
|
cognos79
Posting Yak Master
241 Posts |
Posted - 2007-11-20 : 10:21:33
|
when you execute exec (@TSQL) you get the result. no point in writing select statment after that and you cant do that. |
 |
|
Van
Constraint Violating Yak Guru
462 Posts |
Posted - 2007-11-20 : 11:21:34
|
Right. I put his select statement inside of the @tsql. |
 |
|
|
|
|