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
 General SQL Server Forums
 New to SQL Server Programming
 Comma Separation

Author  Topic 

aoriju
Posting Yak Master

156 Posts

Posted - 2009-03-31 : 06:51:29

DECLARE @astr_Item_Ids VARCHAR(8000)
DECLARE @astr_Item_Ids_Temp VARCHAR(8000)
SET @astr_Item_Ids ='1233,2345,2315,3453,3454,3453,3453,9999';


I want the Answer in @astr_Item_Ids_Temp Like '1233,2345,2315,3453,3454,3453,3453,'
Avoid the Values After The Last Comma

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-03-31 : 06:59:51
this ???

DECLARE @astr_Item_Ids VARCHAR(8000)
DECLARE @astr_Item_Ids_Temp VARCHAR(8000)
SET @astr_Item_Ids ='1233,2345,2315,3453,3454,3453,3453,9999'

print reverse(substring(reverse(@astr_Item_Ids),charindex(',',reverse(@astr_Item_Ids))+1,len(@astr_Item_Ids)))
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-31 : 07:33:54
ANY value after last comma, ur just the value 9999?



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-03-31 : 09:43:17
Other method

print left(@astr_Item_Ids,len(@astr_Item_Ids)-charindex(',',reverse(@astr_Item_Ids)))

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -