getting name value from a string using TSQL
-
29-09-2019 - |
문제
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
해결책
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
다른 팁
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.
제휴하지 않습니다 StackOverflow