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 |
|
mavershang
Posting Yak Master
111 Posts |
Posted - 2009-05-22 : 14:41:43
|
| Hi there, this code does not work.=================================================declare @schema nvarchar(255)delcare @SQL nvarchar(4000)SET @schema='......' (long, skip)SET @SQL='.......' (long, skip)create table #608Combined (DummyCOl INT)EXEC (' ALTER TABLE #608Combined ADD ' + @schema + '; ALTER TABLE #608Combined DROP COLUMN DummyCol; EXEC ('''INSERT #608Combined '''+ @SQL + ''')');==========================================The error is like "incorrect syntax near INSERT".Anyone could help me?Thanks a lot. |
|
|
mavershang
Posting Yak Master
111 Posts |
Posted - 2009-05-22 : 14:55:40
|
I just changed the apostrophe a little bit as below:EXEC (' ALTER TABLE #608Combined ADD ' + @schema + '; ALTER TABLE #608Combined DROP COLUMN DummyCol; EXEC (''INSERT #608Combined '+ @SQL + ''')');Now it works. However, I totally do not understand the reason for that.Anyone could tell me about that?Thanksquote: Originally posted by mavershang Hi there, this code does not work.=================================================declare @schema nvarchar(255)delcare @SQL nvarchar(4000)SET @schema='......' (long, skip)SET @SQL='.......' (long, skip)create table #608Combined (DummyCOl INT)EXEC (' ALTER TABLE #608Combined ADD ' + @schema + '; ALTER TABLE #608Combined DROP COLUMN DummyCol; EXEC ('''INSERT #608Combined '''+ @SQL + ''')');==========================================The error is like "incorrect syntax near INSERT".Anyone could help me?Thanks a lot.
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
mavershang
Posting Yak Master
111 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-05-25 : 13:56:34
|
| welcome |
 |
|
|
|
|
|