79190441

Date: 2024-11-14 21:21:50
Score: 0.5
Natty:
Report link

Not sure when it started, but in SQL Server 2019 you can use FOR JSON AUTO:

select LEFT(@@VERSION,38) as "SQL Server Version is" ,p.person_id ,p.person_name ,a.pet_id ,a.pet_name from @Persons p join @Pets a on p.person_id = a.pet_owner FOR JSON AUTO

Result: [ { "SQL Server Version is": "Microsoft SQL Server 2019 (RTM-CU28-GD", "person_id": 2, "person_name": "Jack", "a": [ { "pet_id": 4, "pet_name": "Bug" }, { "pet_id": 5, "pet_name": "Feature" } ] }, { "SQL Server Version is": "Microsoft SQL Server 2019 (RTM-CU28-GD", "person_id": 3, "person_name": "Jill", "a": [ { "pet_id": 6, "pet_name": "Fiend" } ] } ]

Reasons:
  • Whitelisted phrase (-1.5): you can use
  • Long answer (-0.5):
  • No code block (0.5):
  • User mentioned (1): @Persons
  • User mentioned (0): @Pets
  • Low reputation (1):
Posted by: LOCOCHON2020