Home All Groups Group Topic Archive Search About
Author
12 Jan 2006 1:27 PM
marcmc
I just can't seem to get the apostraphes right in this piece of dynamic sql.
Any ideas?

declare @marc varchar(4), @marc1 varchar(8)
select @marc = 'marc'
select @marc1 = 'QUINN_WH'

EXEC('INSERT INTO marc_QMR_SNAPS_bug_Fix VALUES(' + @marc + 'Table Index
created, getdate()')

Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'Index'.

Author
12 Jan 2006 1:31 PM
ML
Try printing it before you try to execute it, then copy the result to a new
QA window and try parsing it there.

I bet you'll see the problem right away.


ML

---
http://milambda.blogspot.com/
Author
12 Jan 2006 1:35 PM
SQL
yes use the print statement, but this should do it

declare @marc varchar(4), @marc1 varchar(8)
select @marc = 'marc'
select @marc1 = 'QUINN_WH'


exec('INSERT INTO marc_QMR_SNAPS_bug_Fix VALUES(''' + @marc +
''',''Table Index
created'', getdate()')


http://sqlservercode.blogspot.com/
Author
12 Jan 2006 2:20 PM
marcmc
havn't got it yet
there are only two columns in the table, it should print as:

INSERT INTO marc_QMR_SNAPS_bug_Fix VALUES('marc Table Index created',
getdate()
Author
12 Jan 2006 2:26 PM
SQL
Try this

declare @marc varchar(4), @marc1 varchar(8)
select @marc = 'marc'
select @marc1 = 'QUINN_WH'


print('INSERT INTO marc_QMR_SNAPS_bug_Fix VALUES(''' + @marc +
' Table Index
created'', getdate())')

exec('INSERT INTO marc_QMR_SNAPS_bug_Fix VALUES(''' + @marc +
' Table Index
created'', getdate())')


http://sqlservercode.blogspot.com/
Author
12 Jan 2006 3:48 PM
marcmc
thanking you

Show quote
"SQL" wrote:

> Try this
>
> declare @marc varchar(4), @marc1 varchar(8)
> select @marc = 'marc'
> select @marc1 = 'QUINN_WH'
>
>
> print('INSERT INTO marc_QMR_SNAPS_bug_Fix VALUES(''' + @marc +
> ' Table Index
> created'', getdate())')
>
> exec('INSERT INTO marc_QMR_SNAPS_bug_Fix VALUES(''' + @marc +
> ' Table Index
> created'', getdate())')
>
>
> http://sqlservercode.blogspot.com/
>
>

AddThis Social Bookmark Button