[英]Is there a LIKE operator for a dynamic list or set of multiple strings on MS SQL Server?
[英]Get count of multiple Ints in array in multiple JSON strings in MS SQL Server
我一直在搜索这个主题,我找到了处理字符串的例子,但关于 arrays 的例子不多。 我从存储在单个列中的 JSON 字符串开始,看起来像这样......
然后我可以使用这个查询来提取每条记录的 Ids 部分......
SELECT Id, Message,
JSON_QUERY(Message, 'strict$.Ids') AS Ids
FROM ActionQueue
WHERE Status = 1
AND (Action = 'Approve' OR Action = 'Reject')
我现在需要将那些 arrays(不确定它们是否是看起来像 arrays 的字符串?)组合成一个数组。
我需要使用该 Id 列表来传递给存储过程以及获取 Id 的计数。
declare @t table(thejsoncolumn nvarchar(max));
insert into @t(thejsoncolumn)
values(N'{"Ids":[1, 2, 3, 4, 5]}'), (N'{"Ids":[7]}'), (N'{"Ids":[6, 9, 10, 11]}');
select stuff(
(select concat(',', value)
--string_agg(value, ',') within group (order by cast(value as int)) AS thelist
from
(
select distinct j.value
from @t as t
cross apply openjson(t.thejsoncolumn, '$.Ids') as j
) as src
order by cast(value as int)
for xml path('') --..numbers only
), 1, 1, '');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.