我正在使用SQL Server 2014。我有一列中包含文本數據。數據是這樣的:SQL中的字符串操作
create table #temp
(
stringdata varchar(100) NULL
)
insert into #temp values
('CN=ABCD,PN=XYZ,AD=123,AN=rst'),
('AN=ABC,PN=XYZ,CN=12,AN=rst'),
('AN=ABC,CN=XYZ,PN=123,AN=rst'),
('AN=ABC,AN=XYZ,CN=1234567,PN=rst')
我需要被映射爲CN
結果的設定值。
我試着用下面的查詢來提取數據:
select substring(stringdata,charindex('CN=',stringdata),charindex(',',stringdata)-1),*
from #temp
但問題是,它需要逗號值的第一個指數。我無法提供正確的長度。
是否有任何簡單的查詢來獲取數據?
它的SQL服務器2014 – Remi