By using a statement like this:
insert into tbl_temp (name,tel) values (@txt)
You are telling SQL that @txt is the value for the "name" column and you aren't providing a value for "tel". Furthermore, if this worked the way you want it to the actual value that would end up in "name" would be "'david','01-555555'".
You need to provide each value independently.
declare @name varchar(100)
declare @tel varchar(100)
select @name='david'
select @tel='01-555555'
insert into tbl_temp (name,tel) values (@name,@tel)
Alternatively, you could build the SQL to execute on the fly:
declare @txt varchar(100)
select @txt='''david'',''01-555555'''
EXECUTE('insert into tbl_temp (name,tel) values ('+@txt+')')
However, I would advise against this. It gets very messy and I think that it doesn't help performance. If you have to to accessive amounts of query construction in a stored procedure you should reconsider your database design.
Peter
------------------------------------------------------
Work smarter, not harder.
|