|
|
|
Say Hey Kid
      
Group: General Forum Members
Last Login: Tuesday, May 07, 2013 6:56 AM
Points: 679,
Visits: 953
|
|
HI,
I need to create a function that receives a parameter (string) and returns a value if there is a second '*' in the string.
E.g:
Function receives the string:
*4112*21211222
returns number 6
Other e.g
Function receives the string:
*411221211*222
returns number 11
Other e.g
Function receives the string:
411221211222
returns nothing, because there is no second *
Can someone help me with the t-sql to do this?
Thnak you
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Wednesday, May 08, 2013 7:42 AM
Points: 2,802,
Visits: 7,103
|
|
declare @SearchString varchar(100) set @SearchString = '*411221211*222' select charindex('*',@SearchString,CHARINDEX('*',@SearchString,1)+1)
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Sunday, March 03, 2013 2:50 AM
Points: 112,
Visits: 294
|
|
IF LEN(@string) - LEN(REPLACE(@string, '*', '')) >= 2 BEGIN RETURN LEN(@string) - CHARINDEX('*', REVERSE(@string)) + 1 END
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Yesterday @ 11:38 PM
Points: 194,
Visits: 685
|
|
Use this:Select CHARINDEX('*',@InputString,CHARINDEX('*',@InputString, 1) + 1) Returns 0 if it doesn't find a second '*'.
edit: too late
|
|
|
|
|
Say Hey Kid
      
Group: General Forum Members
Last Login: Tuesday, May 07, 2013 6:56 AM
Points: 679,
Visits: 953
|
|
|
|
|