我有一个类似的领域 okbogkbogkbokgbokgobkgobkofkgbokfgbo&name=fokdofkd&okfaos
okbogkbogkbokgbokgobkgobkofkgbokfgbo&name=fokdofkd&okfaos
我想name = value从数据中提取。
name = value
如何使用SQL Server 2008高效地做到这一点?谢谢你
试试这个
; With MyTable as ( SELECT 'okbogkbogkbokgbokgobkgobkofkgbokfgbo&name=fokdofkd&okfaos' FullString UNION SELECT 'fkgbokfgbo&name=fokdofkd&okfaos' FullString UNION SELECT 'okbogkbogkbokgbok' FullString ), PatternIndex as ( Select FullString + '&' FullString, CharIndex ('&name=', FullString) + 1 LocationOfEqualSign, CharIndex ('&', FullString, CharIndex ('&name=', FullString)+1) as NextBreak from MyTable ), SplitNameValue AS ( Select FullString, CASE WHEN NextBreak <> 0 THEN SubString (FullString, LocationOfEqualSign, NextBreak-LocationOfEqualSign) ELSE '' END as NameValuePair From PatternIndex ) SELECT * FROM SplitNameValue
退货
FullString NameValuePair --------------------------------------------------------- --------------------------------------------------------- fkgbokfgbo&name=fokdofkd&okfaos name=fokdofkd okbogkbogkbokgbok okbogkbogkbokgbokgobkgobkofkgbokfgbo&name=fokdofkd&okfaos name=fokdofkd (3 row(s) affected)