September 19, 2005 at 7:35 am
Can someone help, I've been getting an error meesage when I execute this code
declare @sDescription as varchar(1000)
declare @sSkill as varchar(1000)
declare @sFallback as varchar(1000)
declare @swmskill as varchar(1000)
declare @sql as varchar(5000)
set @sDescription = 'crap2'
set @sSkill = 'crap4'
set @sFallback = 'crap1'
set @swmskill = 'crap5'
set @sql = ' INSERT INTO [TRC] ([Description2],Skill, Fallback,wmskill) VALUES (' + @sDescription + ',' + @sSkill + ',' + @sFallback + ',' + @swmskill + ')'
exec (@sql)
The error message is :-
Server: Msg 128, Level 15, State 1, Line 1
The name 'crap2' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.
can anyone help please
September 19, 2005 at 7:39 am
If you had seen the @sql value just before executing it, you will know whats wrong.
You have to have another single quote in front of each variable. Something like this:
set @sql = ' INSERT INTO [TRC] ([Description2],Skill, Fallback,wmskill) VALUES (' + '''' + @sDescription + '''' + ',' + '''' + @sSkill + '''' + ',' + '''' + @sFallback + '''' + ',' + @swmskill + '''' + ')'
Thanks,
Ganesh
September 19, 2005 at 7:46 am
Why are you using dynamic sql for this???
September 19, 2005 at 7:55 am
What I posted wasn't the complete code, it was from a stored procedure which allowed me to specify the table name from vb code, I was testing it in the sql query analyzer, but to simplify debugging I hard coded the table name
September 19, 2005 at 7:55 am
many thanks for the assistance, it works great now
September 19, 2005 at 8:08 am
I strongly suggest you read this :
September 19, 2005 at 8:12 am
thanks for the info, makes an interesting read
September 19, 2005 at 8:57 am
print @VariableName
then execute from QA
September 19, 2005 at 9:19 am
thanks
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply