如何查询json数组字段。
我的sql表字段是个人数据,示例数据在下面
[{"Name":"A","Age":"12"},
{"Name":"B","Age":"22"},
{"Name":"C","Age":"22"}]
因此所需的查询类似于Name = A
答案 0 :(得分:0)
这应该将JSON设置为可以正常查询的格式:
select
SUBSTRING([name], CHARINDEX(':', [name]) + 1, 8000) as [name]
,SUBSTRING([age], CHARINDEX(':', [age]) + 1, 8000) as [name]
from
(select
SUBSTRING(value, 1, CHARINDEX(',', value) - 1) AS [name]
,SUBSTRING(value, CHARINDEX(':',value)+3,CHARINDEX(',',value)-1) as [age]
from
(select replace(replace(replace(replace(strTest, '[', ''), '}', ''), ']', ''), '"', '') as strMod
from [dbo].[tblTest]
) as a
cross apply string_split(strMod, '{')
where value <> ''
) as b