Subject: insert concatinate string problem :(
Posted By: meemee Post Date: 2/10/2004 11:48:27 PM
i can not insert the concatinate string into db (stored procedure)

declare @txt varchar(100)
select @txt='''david'',''01-555555'''
insert into tbl_temp (name,tel) values (@txt)

can i do like this ?
how to do it
thanks

Reply By: mateenmohd Reply Date: 2/11/2004 2:51:05 AM
try this

select @txt=david+01-555555 as name

insert into tbl_temp (name) values (@txt)




quote:
Originally posted by meemee

i can not insert the concatinate string into db (stored procedure)

declare @txt varchar(100)
select @txt='''david'',''01-555555'''

insert into tbl_temp (name,tel) values (@txt)

can i do like this ?
how to do it
thanks

 



Reply By: planoie Reply Date: 2/11/2004 8:05:17 PM
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.

Go to topic 9674

Return to index page 950
Return to index page 949
Return to index page 948
Return to index page 947
Return to index page 946
Return to index page 945
Return to index page 944
Return to index page 943
Return to index page 942
Return to index page 941