0

I just edited the question to make it more clear.. please help

I am using SQL server 2008.

I have a column containing the following strings..

http://www.microsoft.com?abc=1234&def=567&ghi=891
http://www.microsoft.com?abc=4587&def=567&ghi=891
http://www.microsoft.com?abc=2478&def=567&ghi=891
http://www.microsoft.com?abc=9874&def=567&ghi=891
http://www.microsoft.com?abc=5412&def=567&ghi=891

In the following string, how can I get values of "abc" using TSQL?

the result should be ...

abc

1234
4587
2478
9874
5412

Please let me know.

thanks

4
  • Are you reading this from a table or trying to parse some input? Also do you expect the position of abc to change or is it expected to be a static bit of data? Commented Nov 8, 2010 at 22:48
  • Are you only looking for the first parameter, or all parameters in the URL string? Commented Nov 8, 2010 at 22:49
  • I do no expect position of abc to change. Commented Nov 9, 2010 at 0:09
  • I am only looking for first parameter 'abc' Commented Nov 9, 2010 at 0:09

2 Answers 2

3
declare @x varchar(100)
set @x = 'http://www.microsoft.com?abc=1234&def=567&ghi=891'

declare @param varchar(100)

set @param = 'abc='
select SUBSTRING(@x, charindex(@param, @x)+LEN(@param), CHARINDEX('&', @x+'&', charindex(@param, @x)) - CHARINDEX(@param, @x)-LEN(@param)) as abc

set @param = 'def='
select SUBSTRING(@x, charindex(@param, @x)+LEN(@param), CHARINDEX('&', @x+'&', charindex(@param, @x)) - CHARINDEX(@param, @x)-LEN(@param)) as def

set @param = 'ghi='
select SUBSTRING(@x, charindex(@param, @x)+LEN(@param), CHARINDEX('&', @x+'&', charindex(@param, @x)) - CHARINDEX(@param, @x)-LEN(@param)) as ghi
Sign up to request clarification or add additional context in comments.

Comments

0

you can use the substring method on t-sql, but you would have to know the start and length parameters. i mean if the string value changes, it won't work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.