Groups | Blog | Home
all groups > sql server (alternate) > january 2004 >

sql server (alternate) : Extract a string in a Stored Procedure


laurenquantrell NO[at]SPAM hotmail.com
1/13/2004 2:04:57 PM
Is there anyway to extract part of a string in a stored procedure
using a parameter as the starting point?
For example, my string might read: x234y01zx567y07zx541y04z
My Parameter is an nvarchar and the value is: "x567y"
What I want to extract is the two charachters after the parameter, in
this case "07".
Can anyone shed some light on this problem?
Thanks,
Erland Sommarskog
1/13/2004 10:15:37 PM
Lauren Quantrell (laurenquantrell@hotmail.com) writes:
[quoted text, click to view]

Looks like a combination of substring and charindex (or possibly
patindex) is what you need. I recommend that you use the SQL Server
Books Online to study all the string functions that SQL Server
offers. They are not that many, and not that extremely powerful, but
it's very useful to know them.


--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se

Books Online for SQL Server SP3 at
laurenquantrell NO[at]SPAM hotmail.com
1/15/2004 8:48:55 AM
Thanks.
I'm on a crash project using MDSE and don't have immediate access to
Books Online though...
lq

[quoted text, click to view]
laurenquantrell NO[at]SPAM hotmail.com
1/15/2004 2:33:09 PM
I figured out how to do this:

substring(mystring,charindex(@parameter,myString)+len(@parameter),2)

where @parameter = 'x' + [myUserID] + 'y'

Thanks for pointing me in the right direction.

lq


[quoted text, click to view]
Erland Sommarskog
1/15/2004 10:48:33 PM
Lauren Quantrell (laurenquantrell@hotmail.com) writes:
[quoted text, click to view]

You have. Check my signature.


--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se

Books Online for SQL Server SP3 at
AddThis Social Bookmark Button