我有一个名为 A 的表,其中有多列,其中一列由 json 组成,我在其中插入设置。
例如该列包含 .
{"ID":"79","NameEn":"Medical - Gross Premiums by Company (TTM) (%)","NameAr":"الحصة من أقساط القطاع الصحي (%) (آخر 12 شهراً)","Key":"insurance-ranking","apiEndPoint":"tools-ranking","uidMapping":"6","sn":"0","ac":"0","arg":"companyids,tcid,language,tcvalue,companyid","UID":"6-15-79-44-T","fiscalPeriods":{"periods":"[]","IsSelected":""},"fiscalYEars":{"years":"[]","fullViewYears":"[]","IsSelected":""},"tbc":"[1,2,3]"}
如上所示,它包含不同的键及其值,我想返回记录,但我想应用 NameEn 和 NameAr 中的特定条件,我只想返回包含括号的部分,并排除其余部分。
例如:上面一行我想要的结果是
{"ID":"79","NameEn":"(TTM) (%)","NameAr":" (%) (آخر 12 شهراً)","Key":"insurance-ranking","apiEndPoint":"tools-ranking","uidMapping":"6","sn":"0","ac":"0","arg":"companyids,tcid,language,tcvalue,companyid","UID":"6-15-79-44-T","fiscalPeriods":{"periods":"[]","IsSelected":""},"fiscalYEars":{"years":"[]","fullViewYears":"[]","IsSelected":""},"tbc":"[1,2,3]"}
我使用了以下逻辑,我选择第一个括号并从那里获取所有子字符串
SUBSTRING(JSON_VALUE(Parameters,'$.NameEn') ,CHARINDEX('(',JSON_VALUE(Parameters,'$.NameEn'))+0,LEN(JSON_VALUE(Parameters,'$.NameEn'))) UnitsEn