Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 11th, 2004, 12:48 AM
Registered User
 
Join Date: Feb 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default insert concatinate string problem :(

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

 
Old February 11th, 2004, 03:51 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

try this

select @txt=david+01-555555 as name

insert into tbl_temp (name) values (@txt)




Quote:
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

 
Old February 11th, 2004, 09:05 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Using INSERT INTO with a string Variable Suspect Access VBA 2 January 6th, 2015 11:25 AM
how to insert these string into database SpringSummer SQL Language 3 September 22nd, 2007 07:05 AM
String to DateTIme for Insert plymnet Classic ASP Databases 1 August 21st, 2005 11:09 PM
Insert HTML at certain point in string. interrupt Javascript How-To 1 June 13th, 2005 07:21 AM
How Do I Concatinate fields into a key field Brian263 Access 1 May 3rd, 2004 03:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.