Selecting data using JSON in sql server:
SELECT gid, email FROM tempEmails FOR json auto
Selecting Column Values From JSON Format in sql server:
For Example the below is the JSON format:
[{"gid":"0000036285","email":"tetsuya.ono@gmail.com,tetsuya.ono@gmail.com"},{"gid":"0000047244","email":"Miyuki.Yamamoto@gmail.com"}]
select JSON_Value(JSON_F52E2B61-18A1-11d1-B105-00805F49916B,'$.gid') as gid
JSON_Value(JSON_F52E2B61-18A1-11d1-B105-00805F49916B,'$.email') as email
;WITH CTE ([JSON_F52E2B61-18A1-11d1-B105-00805F49916B])
as
(
SELECT TOP 2 gid, email FROM tempEmails FOR json auto
)
,CTE1 (JSONValue) AS
(
select [JSON_F52E2B61-18A1-11d1-B105-00805F49916B] JSONValue from cte
)
SELECT JSON_Value(JSONValue,'$[0].gid') as gid,
JSON_Value(JSONValue,'$[0].email') as email FROM CTE1
SELECT gid, email FROM tempEmails FOR json auto
Selecting Column Values From JSON Format in sql server:
For Example the below is the JSON format:
[{"gid":"0000036285","email":"tetsuya.ono@gmail.com,tetsuya.ono@gmail.com"},{"gid":"0000047244","email":"Miyuki.Yamamoto@gmail.com"}]
select JSON_Value(JSON_F52E2B61-18A1-11d1-B105-00805F49916B,'$.gid') as gid
JSON_Value(JSON_F52E2B61-18A1-11d1-B105-00805F49916B,'$.email') as email
;WITH CTE ([JSON_F52E2B61-18A1-11d1-B105-00805F49916B])
as
(
SELECT TOP 2 gid, email FROM tempEmails FOR json auto
)
,CTE1 (JSONValue) AS
(
select [JSON_F52E2B61-18A1-11d1-B105-00805F49916B] JSONValue from cte
)
SELECT JSON_Value(JSONValue,'$[0].gid') as gid,
JSON_Value(JSONValue,'$[0].email') as email FROM CTE1
No comments:
Post a Comment