我正在努力对子字符串进行子字符串化并获取 SQL 中的值。
我有一个 JSON 字符串,如下所示:
DECLARE @string varchar(max)= '[{"CustomFieldId":18,"FieldName":"ABCD","FieldType":"freeText","FieldValue":null,"Details":null,"Value":null,"RelationTable":null,"Isisible":true,"IsAdmin":false,"CreatedDate":null,"ModifiedDate":null,"LoggedInUser":"TESTUSER"},{"CustomFieldId":19,"FieldName":"Workdomain","FieldType":"freeText","FieldValue":null,"Details":null,"Value":null,"RelationTable":null,"IsVisible":true,"IsAdmin":false,"CreatedDate":null,"ModifiedDate":null,"LoggedInUser":"149645"},{"CustomFieldId":20,"FieldName":"TEST1234","FieldType":"freeText","FieldValue":"Sometest","Details":null,"Value":null,"RelationTable":null,"IsVisible":false,"IsAdmin":false,"CreatedDate":null,"ModifiedDate":null,"_listlovFields":[],"org4Values":[],"LoggedInUser":"TESTUSER"}]'
或者也可以是这样的:
DECLARE @string varchar(max) = '[{"CustomFieldId":20,"FieldName":"TEST1234","FieldType":"freeText","FieldValue":"Sometest","Details":null,"Value":null,"RelationTable":null,"IsVisible":false,"IsAdmin":false,"CreatedDate":null,"ModifiedDate":null,"LoggedInUser":"TESTUSER"}]'
现在,我需要从其中任何一个那里获取具有特定“FieldName”的特定“CustomFieldId”的“FieldValue”,并且该 FieldValue 以特定字符串开头。
就像,我会得到这些:
declare @propName varchar(max) = 'Test1234',
@customFieldId varchar(max) = 20,
@value varchar(max) = 'Some'
因此,在这种特殊情况下,我需要使用 CustomFieldId:"20", FieldName":"TEST1234" 以及 FieldValue 以“Some”开头的自定义字段的 FieldValue。
输出只需要字符串“Sometest”,因为这是 CustomFieldId 的 FieldValue:"20"
对此的任何帮助将不胜感激。