Log in  ::  Register  ::  Not logged in

 Recent PostsRecent Posts Popular TopicsPopular Topics
 Home Search Members Calendar Who's On

 Split based on the input Rate Topic Display Mode Topic Options
Author
 Message
 Posted Wednesday, January 02, 2013 3:22 AM
 SSC-Enthusiastic Group: General Forum Members Last Login: Yesterday @ 2:53 AM Points: 111, Visits: 517
 hihow to split the string based on the input say starting is 1 and next is also 1 the difference is 1say starting is 2 and next is also 1 the difference is 1say starting is 3 and next is also 5 the difference is 5declare @input varchar(1000)='1,1,5,5,6,2'start end,difference1,1,12(start+difference),2,13(start+difference),7,58(start+difference),12,513(start+difference),18,619(start+difference),20,2Thanks!
Post #1401733
 Posted Wednesday, January 02, 2013 5:37 AM
 SSC-Enthusiastic Group: General Forum Members Last Login: Yesterday @ 2:53 AM Points: 111, Visits: 517
 hi,declare @input varchar(1000)='1,1,5,5,6,2'start, difference1,12,13,58,513,619,2Godeclare @input varchar(1000)='5,3,2'start, difference1,56,39,2
Post #1401796
 Posted Wednesday, January 02, 2013 6:28 AM
 SSC-Enthusiastic Group: General Forum Members Last Login: Yesterday @ 2:53 AM Points: 111, Visits: 517
 I got it thanks!!Create Function [dbo].[Splited_Values]( @CommaSeparatedString varchar(8000))RETURNS @Table Table ( startid int,ID int)Begin Declare @TempStr varchar(8000) ,@tempval int=1 Set @TempStr = @CommaSeparatedString + ',' While Len(@TempStr) > 0 Begin Insert Into @Table Select @tempval,SubString(@TempStr,1,CharIndex(',',@TempStr)-1) Set @tempval= @tempval+SubString(@TempStr,1,CharIndex(',',@TempStr)-1) Set @TempStr = Right(@TempStr,Len(@TempStr)-CharIndex(',',@TempStr)) End ReturnEnd
Post #1401810

 Permissions

 Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved. Privacy Policy. Terms of Use. Report Abuse.