September 26, 2005 at 1:13 am
Lo to all,
I hope someone can help.
my questions is:
i have a string " where strs in ('40301','40301.16') "
i need to take out only '40301' , '40301.16' from the string.
how can i do that?
thanks.
September 26, 2005 at 3:06 am
Look up charindex and substring in Books online.
Basically, use Charindex to find the location of the quotes in the string, then substring to extract the portion you want.
DECLARE @STR VARCHAR(15)
SET @STR='ABC(XYZ)CBA'
SELECT SUBSTRING(@str,CHARINDEX('(',@str), LEN(@str)+1-(CHARINDEX(')',@str)-1))
hth
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 26, 2005 at 4:22 am
The quotes are in the wrong place. Try this
set @STR = ' where strs in (''40301'',''40301.16'') '
The rest of atra's query should be fine.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 26, 2005 at 4:27 am
SQL's not overly fond of double quotes. In fact, if quoted identifiers is set on (which is a default) your query returns the following error
Server: Msg 207, Level 16, State 3, Line 3
Invalid column name ' where strs in ('40301','40301.16') '.
Stick with single quotes and escape them as necessary.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 26, 2005 at 4:31 am
Thanks a lot its working
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply