WITH TBL AS
(
SELECT 1 AS ID, 'PARK' AS NAME, 45 AS AGE
UNION ALL
SELECT 2 AS ID, 'HWANG' AS NAME, 41 AS AGE
UNION ALL
SELECT 3 AS ID, 'KIM' AS NAME, 23 AS AGE
UNION ALL
SELECT 4 AS ID, 'MOON' AS NAME, 34 AS AGE
)
SELECT NAME, AGE
FROM TBL
FOR JSON AUTO;
JSON_F52E2B61-18A1-11d1-B105-00805F49916B |
-----------------------------------------------------------------------------------------------------|
[{"NAME":"PARK","AGE":45},{"NAME":"HWANG","AGE":41},{"NAME":"KIM","AGE":23},{"NAME":"MOON","AGE":34}]|
WITH TBL AS
(
SELECT 1 AS ID, 'PARK' AS NAME, 45 AS AGE
UNION ALL
SELECT 2 AS ID, 'HWANG' AS NAME, 41 AS AGE
UNION ALL
SELECT 3 AS ID, 'KIM' AS NAME, 23 AS AGE
UNION ALL
SELECT 4 AS ID, 'MOON' AS NAME, 34 AS AGE
)
SELECT NAME, AGE
FROM TBL
FOR JSON AUTO , WITHOUT_ARRAY_WRAPPER;
JSON_F52E2B61-18A1-11d1-B105-00805F49916B |
---------------------------------------------------------------------------------------------------|
{"NAME":"PARK","AGE":45},{"NAME":"HWANG","AGE":41},{"NAME":"KIM","AGE":23},{"NAME":"MOON","AGE":34}|
WITH TBL AS
(
SELECT 1 AS ID, 'PARK' AS NAME, 45 AS AGE
UNION ALL
SELECT 2 AS ID, 'HWANG' AS NAME, 41 AS AGE
UNION ALL
SELECT 3 AS ID, 'KIM' AS NAME, 23 AS AGE
UNION ALL
SELECT 4 AS ID, 'MOON' AS NAME, 34 AS AGE
)
SELECT ID
, (SELECT NAME, AGE FOR JSON PATH, WITHOUT_ARRAY_WRAPPER) AS VALUE
FROM TBL;
ID|VALUE |
--|-------------------------|
1|{"NAME":"PARK","AGE":45} |
2|{"NAME":"HWANG","AGE":41}|
3|{"NAME":"KIM","AGE":23} |
4|{"NAME":"MOON","AGE":34} |
-- JSON String을 Row level JSON String으로
DECLARE @json NVARCHAR(MAX)
SET @json = (SELECT NAME, AGE
FROM (SELECT 1 AS ID, 'PARK' AS NAME, 45 AS AGE
UNION ALL
SELECT 2 AS ID, 'HWANG' AS NAME, 41 AS AGE
UNION ALL
SELECT 3 AS ID, 'KIM' AS NAME, 23 AS AGE
UNION ALL
SELECT 4 AS ID, 'MOON' AS NAME, 34 AS AGE) TBL
FOR JSON AUTO)
SELECT value
FROM OPENJSON(@json);
value |
-------------------------|
{"NAME":"PARK","AGE":45} |
{"NAME":"HWANG","AGE":41}|
{"NAME":"KIM","AGE":23} |
{"NAME":"MOON","AGE":34} |
json type으로 결과 조회 하기
|
2020.11.27 09:33:10
|
2020.11.27 09:33:10
|
439
|
Aiden
Total of Attached file
0.00 Bytes of 0 files
2021.07.22
2021.05.21
2021.04.30
2020.11.27
2020.10.28
2020.08.20
2019.02.21
2018.06.11