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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-03-03 : 08:45:28
|
| chinimimita writes "I will create a SP which one of the paramater is the tablename, so basically I need to use exec command. But I'm thinking, what if the @sql variable will reach it maximum length then I will encounter error. Is there anyway to do this without storing the whole sql command to @sql string?---declare @aa varchar(500)declare @tablename varchar(500)declare @sql varchar(1000)select @tablename = 'mytable'set @sql = 'select * from ' + @tablename exec (@sql)" |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-03-03 : 08:54:20
|
| One of the methods isexec ('select * from ' + @tablename)MadhivananFailing to plan is Planning to fail |
 |
|
|
blindman
Master Smack Fu Yak Hacker
2365 Posts |
Posted - 2006-03-03 : 09:36:54
|
| You can break your SQL statement into separate strings (SELECT, FROM, WHERE, GROUP BY, whatever...) and then concatenate them with your EXEC statement. The EXEC statement can handled concatenated strings that exceed the 8000 character limit of the varchar datatype. |
 |
|
|
|
|
|