|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Syntax pleaseI 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'. 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/ 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/ 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() 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/ 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/ > > |
|||||||||||||||||||||||