Opengist

Explore

  • All gists
  • Topics
  • Users
Give feedback on the new UI Powered by Opengist ⋅ 98ms

user:thomas gists created by user

title:mygist gists with given title

description:sync gists with given description

filename:myfile.txt gists having files with given name

extension:yml gists having files with given extension

language:go gists having files with given language

topic:homelab gists with given topic

all:systemctl search all fields

Login
s

sql-tips

Recently created Least recently created Recently updated Least recently updated

timmy / 🧾 SQL Server 輸出 JSON:FOR JSON PATH 超簡單上手

Last active 6 hours ago data-api for-json json-output sql-query sql-server sql-tips

用 SQL Server 直接產出 JSON,支援巢狀資料結構與根物件命名,後端串接 REST API 不再痛苦 🙌

0 0 0 1
1 SELECT id, name, age -- 選取 id、name 和 age 欄位
2 FROM YourTable -- 從 YourTable 查詢
3 FOR JSON PATH; -- 以 JSON 格式輸出,允許自訂 JSON 結構
4
5 SELECT id, name, age -- 選取 id、name 和 age 欄位
6 FROM YourTable -- 從 YourTable 查詢
7 FOR JSON PATH, ROOT('Users'); -- 以 JSON 格式輸出,並加上 "Users" 作為根物件