Javascript

Sqlserver Json

本文主要是介绍Sqlserver Json,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
append3 字段的sql格式如下
[
{"ID":1,"Name":"身高、体重、血压","MerchantsID":681,"MarketPrice":null,"CashPrice":null,"SettlePrice":null,"NormalPrice":null},
{"ID":35,"Name":"肝功能八项","MerchantsID":681,"MarketPrice":null,"CashPrice":null,"SettlePrice":null,"NormalPrice":null},
{"ID":83,"Name":"血糖(餐后3小时)","MerchantsID":681,"MarketPrice":null,"CashPrice":null,"SettlePrice":null,"NormalPrice":null},
{"ID":100,"Name":"血脂四项","MerchantsID":681,"MarketPrice":null,"CashPrice":null,"SettlePrice":null,"NormalPrice":null},
{"ID":105,"Name":"肾功四项","MerchantsID":681,"MarketPrice":null,"CashPrice":null,"SettlePrice":null,"NormalPrice":null},
{"ID":106,"Name":"血常规(五分类)","MerchantsID":681,"MarketPrice":null,"CashPrice":null,"SettlePrice":null,"NormalPrice":null},
{"ID":162,"Name":"胸部正侧位片","MerchantsID":681,"MarketPrice":null,"CashPrice":null,"SettlePrice":null,"NormalPrice":null},
{"ID":202,"Name":"心电图","MerchantsID":681,"MarketPrice":null,"CashPrice":null,"SettlePrice":null,"NormalPrice":null},
{"ID":236,"Name":"乙肝两对半","MerchantsID":681,"MarketPrice":null,"CashPrice":null,"SettlePrice":null,"NormalPrice":null},
{"ID":338,"Name":"肝胆脾胰肾彩超","MerchantsID":681,"MarketPrice":null,"CashPrice":null,"SettlePrice":null,"NormalPrice":null},
{"ID":379,"Name":"尿常规","MerchantsID":681,"MarketPrice":null,"CashPrice":null,"SettlePrice":null,"NormalPrice":null}
]


SELECT
    OrderNo,
    ItemCombId,
    ItemCombName,
    ItemCombMarketPrice,
    ItemCombNormalPrice 
FROM
    T_ShopCart CROSS APPLY OPENJSON ( T_ShopCart.append3, '$' ) WITH (
        ItemCombId VARCHAR ( 200 ) '$.ID',
        ItemCombName VARCHAR ( 200 ) '$.Name',
        ItemCombMarketPrice VARCHAR ( 200 ) '$.MarketPrice',
    ItemCombNormalPrice VARCHAR ( 200 ) '$.NormalPrice' 
    )
    where OrderNo ='22022021516184695133'

 

 

 

简单获取数组json 对象为多列查询效果

SELECT
OrderNo,
appjson.*
FROM
T_ShopCart CROSS APPLY OPENJSON ( T_ShopCart.append3, '$' ) as appjson
where OrderNo ='22022021516184695133'



 

OPENJSON ( T_ShopCart.append3, '$' ) WITH (
        ItemCombId VARCHAR ( 200 ) '$.ID',
        ItemCombName VARCHAR ( 200 ) '$.Name',
        ItemCombMarketPrice VARCHAR ( 200 ) '$.MarketPrice',
    ItemCombNormalPrice VARCHAR ( 200 ) '$.NormalPrice' 
    )
命名获取对象中的值

 

 

官网资料
https://docs.microsoft.com/zh-cn/sql/relational-databases/json/json-data-sql-server?view=sql-server-ver15

 

这篇关于Sqlserver Json的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!