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