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 2008 Forums
 Transact-SQL (2008)
 need query help

Author  Topic 

adiboy0420
Starting Member

10 Posts

Posted - 2012-07-12 : 23:02:22
hello i need help...

so i have a problem ... the input needs to be @x ='abc,1,2,0.5'

( this can be any string put by user)

and the results i need is

abc
1
2
0.5
----------------------------------------------- so my code

declare @x varchar(5000)
declare @y varchar (2000)
declare @z varchar(1000)

set @x ='abc,1,2,0.5'

set @y=@x

while(CHARINDEX(',',@y)>0)

begin

set @z= LEFT(@y,charindex(',',@y)+1)

select @z


set @y= RIGHT(@y,len(@y)-len(@z)-1)

end


and results i get is

abc
1
2

and missing the 0.5.. now if i put the comma at the end of set @x ='abc,1,2,0.5,' it will work.... but i need it the input to me set @x ='abc,1,2,0.5'...


so how do i do this :( please help

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2012-07-12 : 23:26:11
set @y=@x+','
Go to Top of Page

adiboy0420
Starting Member

10 Posts

Posted - 2012-07-13 : 00:40:28
it worked thank you so much
Go to Top of Page
   

- Advertisement -