I would like to create a column that contains JSON with fields calculated based on another table columns. Of course, I can make that as below but that works fine only if the case is quite simple, and still, it is easy to make mistake. Is it a more convenient way to build JSON inside of query?
SELECT
1 AS id, 'AAA' AS ProductCode,
'Camera' AS Product, 5000 AS Price
INTO
#tmp
UNION
SELECT
2 AS id, 'BBB' AS ProductCode,
'Tripod ' AS Product, 80 AS Price
UNION
SELECT
3 AS id, 'CCC' AS ProductCode,
'Objective ' AS Product, 7000 AS Price
SELECT
ProductCode,
'{' + '"Product":"' + Product + '"' + ', '
+ '"Price":"' + cast (Price as nvarchar)
+ '"}' AS Details
FROM
#tmp