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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 any problem with this code?

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?

Thanks

quote:
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.

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-23 : 11:14:59
see this

http://sqlblogcasts.com/blogs/madhivanan/archive/2008/02/19/understanding-single-quotes.aspx
Go to Top of Page

mavershang
Posting Yak Master

111 Posts

Posted - 2009-05-25 : 12:47:48
Thanks a lot.

quote:
Originally posted by visakh16

see this

http://sqlblogcasts.com/blogs/madhivanan/archive/2008/02/19/understanding-single-quotes.aspx


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-25 : 13:56:34
welcome
Go to Top of Page
   

- Advertisement -