hi guys
please help me. i've never user stored procs before but here is my problem.
this is only what i am allowed to display but it shows my problem
declare @.suite varchar(10),@.company varchar(1)
set @.suite = 'brutus'
set @.company = 'A'
exec ('insert into tot (SuiteName,Company) values ('+@.suite+','+@.company+')')
when i exec the query it says that "brutus" is an invalid column name. i know that i need to insert a extra ' but i don't know how or what is the escape character. please help me.
Hi,this should be accomplishedby this one here:
exec ('insert into tot (SuiteName,Company) values ('''+@.suite+''','''+@.company+''')')
But I would rather prefer not using dynamic sql in this case:
insert into tot (SuiteName,Company) values (@.suite,@.company)
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
|||
thanks that helps but when i do this
1. exec ('alter table tot add '+@.UnitT+' varchar(3) DEFAULT '' WITH VALUES')
2. alter table tot add @.UnitT varchar(3) DEFAULT ' ' WITH VALUES
not one work. in 1 i get the same problem and in 2 it tells met there is a problem with syntax before @.unit
|||No, therefore you would need dynamic SQL, that will not function with the second opion I posted.
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
|||OK THANKS
i used your first solution with the ''' multiple quotes and it works perfect. thanks
No comments:
Post a Comment