Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 .NET Inside SQL Server (2005)
 STORED PROCEDURE

Author  Topic 

programer
Posting Yak Master

221 Posts

Posted - 2010-08-10 : 19:10:03
declare @ID nvarchar(50) set @ID ='Name, Address'
declare @Value nvarchar(50) set @Value ='My name, My Address'

if right(rtrim(@ID),1) <> ',' set @ID = @ID + ','


if right(rtrim(@ValuE),1) <> ',' set @Value = @Value + ','

declare @stevc smallint
declare @del_stringa varchar(50)

set @stevc = patindex('%,%',@ID)

set @stevc = patindex('%,%',@Value)

while @stevc <> 0
begin
set @del_stringa = left(@ID, @stevc-1)

set @del_stringa = left(@Value, @stevc-1)


insert into Table2
select @del_stringa
set @ID = stuff(@ID,1,@stevc,'')
set @Value = stuff(@Value,1,@stevc,'')
set @stevc = patindex('%,%',@ID)
set @stevc = patindex('%,%',@Value)

end

My code not work.

This code is intended to simultaneously store data.

ID - works, but not the Value column of additional works.

Need as follows:
Name | My name
Address | My address


Pls help

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-08-11 : 03:46:00
You can't use @stevc for @ID and @Value at the same time.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

CSears
Starting Member

39 Posts

Posted - 2010-08-31 : 14:14:52
You may also want to turn:

quote:
set @del_stringa = left(@ID, @stevc-1)

set @del_stringa = left(@Value, @stevc-1)


into:

quote:

set @del_stringa = left(@ID, @stevc-1) + ' | ' + left(@Value, @stevc2-1)


otherwise you will end up only having the last value that you assigned to @del_stringa, not both.
Go to Top of Page
   

- Advertisement -