Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 substring

Author  Topic 

a.ashabi
Posting Yak Master

117 Posts

Posted - 2009-03-06 : 17:22:09
Hi.I have a field with these values:

72v5468k85/grayfessin.html?type=cf&product_code=BLP3111&refx=g00gx
yuyu222hghdy5/green.html15-48v&product_code=BCD1001&internal=0&refx=lkj100k

I need to have the BCD1001 & BLP3111.

I mean 7 characters after product_code=

plz help me its really urgent.

thanks in advanced

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-03-06 : 17:34:01
assuming your product_code is always 7 characters (as you say it is) - here's one way:

select substring(f, charindex('product_code=', f) + 13, 7)
from (
select '72v5468k85/grayfessin.html?type=cf&product_code=BLP3111&refx=g00gx' f union all
select 'yuyu222hghdy5/green.html15-48v&product_code=BCD1001&internal=0&refx=lkj100k'
) YourTable

OUTPUT:
-------
BLP3111
BCD1001



Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -