小编Ami*_*mir的帖子

json 字段上的“where”导致算术溢出错误

我有一张桌子:

当我从表中选择所有内容时:

 SELECT JSON_VALUE(LastReadings, '$.lastReadings."7-temp".value') as x FROM
(VALUES    
(2,N'{"groups": [],"lastReadings": {"amir": {"name": "Ink","value":12.0},"7-temp": {"name": "Temperature","value":12}},"customId":null}'),
(3,N'{"groups": [],"lastReadings": {"amir": {"name": "Ink","value":12.0},"7-temp": {"name": "Temperature","value":32}},"customId":null}'),
(4,N'{"groups": [],"lastReadings": {"amir": {"name": "Ink","value":12.0},"7-temp": {"name": "Temperature","value":22}},"customId": null}'),
(5,N'{"groups": [],"lastReadings": {"amir": {"name": "Ink","value": 12.0},"7-temp": {"name": "Temperature","value":123}},"customId": null}')    
)
[AmirTestTable](Id,LastReadings )
Run Code Online (Sandbox Code Playgroud)

我得到

+-----+
|  x  |
+-----+
|  12 |
|  32 |
|  22 |
| 123 |
+-----+
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试添加 where 子句时:

 SELECT JSON_VALUE(LastReadings, '$.lastReadings."7-temp".value') as x 
 FROM
(VALUES
  (2,N'{"groups": [],"lastReadings": {"amir": {"name": "Ink","value":12.0},"7-temp": {"name": "Temperature","value":12}},"customId":null}'),
  (3,N'{"groups": …
Run Code Online (Sandbox Code Playgroud)

json sql-server-2016

1
推荐指数
1
解决办法
331
查看次数

标签 统计

json ×1

sql-server-2016 ×1