I have data stored in column as JSON, as shown below:
我将数据存储在列中作为JSON,如下所示:
{"category":{"value":CAT, "demo":A.......
{“category”:{“value”:CAT,“demo”:A .......
I want to query in SSMS and want an output like:
我想在SSMS中查询并希望输出如下:
CAT
猫
I tried "SELECT JSON_QUERY(TABLENAME,'$.CATEGORY') FROM TABLENAME" which gave result of the
我尝试了“从TABLENAME中选择JSON_QUERY(TABLENAME,'$。CATEGORY')”的结果
{"value":CAT, "demo":A....... but I want only CAT. How do I do that?
{“value”:CAT,“demo”:A .......但我只想要CAT。我怎么做?
2 个解决方案
#1
2
Use JSON_VALUE to get specific values.
使用JSON_VALUE获取特定值。
SELECT JSON_VALUE(TABLENAME,'$.CATEGORY.VALUE') AS Value
JSON_QUERY is for JSON fragments.
JSON_QUERY用于JSON片段。
资源
#2
1
You should use JSON_VALUE.
您应该使用JSON_VALUE。
SELECT JSON_VALUE(ColumnName, '$.category.value') FROM TableName
Take note of the first parameter, it should be the column name, not the table name (as opposed to your example).
记下第一个参数,它应该是列名,而不是表名(与您的示例相对)。
#1
2
Use JSON_VALUE to get specific values.
使用JSON_VALUE获取特定值。
SELECT JSON_VALUE(TABLENAME,'$.CATEGORY.VALUE') AS Value
JSON_QUERY is for JSON fragments.
JSON_QUERY用于JSON片段。
资源
#2
1
You should use JSON_VALUE.
您应该使用JSON_VALUE。
SELECT JSON_VALUE(ColumnName, '$.category.value') FROM TableName
Take note of the first parameter, it should be the column name, not the table name (as opposed to your example).
记下第一个参数,它应该是列名,而不是表名(与您的示例相对)。