我有一张桌子:员工。架构:(名称 varchar,首选项 nvarchar(max))。其中,preferences 是一个 json 格式的字符串。
我的查询(失败)是:
select JSON_QUERY(preferences, '$.personal')
from Employee
where ISJSON(preferences) = 1
and len(JSON_QUERY(preferences, '$.personal')) > 2
但是,此查询有效:
select JSON_QUERY(preferences, '$.personal')
from Employee
where ISJSON(preferences) = 1
另外,如果我:
create table tmp(name varchar(256), personal nvarchar(max))
insert into tmp
select name, JSON_QUERY(preferences, '$.personal') as personal
from Employee
where ISJSON(preferences) = 1
select personal
from tmp
where len(personal) > 2
一切正常。
这是 JSON_QUERY() 的 SQL Server 错误还是我做错了什么?
(编辑)错误消息是:
JSON text is not properly formatted. Unexpected character 'n' is found at position 3.
(编辑)也失败了:
select JSON_QUERY(preferences, '$.personal')
from Employee
where ISJSON(preferences) = 1
and JSON_QUERY(preferences, '$.personal') is not null