September 17, 2010 at 3:05 am
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
September 17, 2010 at 3:17 am
declare @SearchString varchar(100)
set @SearchString = '*411221211*222'
select charindex('*',@SearchString,CHARINDEX('*',@SearchString,1)+1)
September 17, 2010 at 3:19 am
IF LEN(@string) - LEN(REPLACE(@string, '*', '')) >= 2
BEGIN
RETURN LEN(@string) - CHARINDEX('*', REVERSE(@string)) + 1
END
September 17, 2010 at 3:19 am
Use this:
Select CHARINDEX('*',@InputString,CHARINDEX('*',@InputString, 1) + 1)
Returns 0 if it doesn't find a second '*'.
edit: too late
September 17, 2010 at 4:00 am
thank you very much
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy