A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
Hi @AgaNeto-3704,
Please refer to:
CREATE TABLE Employees(EmployeeId INT,EmployeeName VARCHAR(15))
INSERT INTO Employees VALUES(1,'Maria'),(2,'Jose'),(3,'Junior')
CREATE TABLE Products(ID INT,ProductName VARCHAR(15),EmployeeId INT)
INSERT INTO Products VALUES(1,'Book',1),(2,'Pen',2),(3,'Box',1)
SELECT REPLACE(REPLACE(REPLACE((SELECT e.*,Products.ProductName
FROM Employees e
JOIN Products Products ON Products.EmployeeId = e.EmployeeId
WHERE e.EmployeeId=1
FOR JSON AUTO),'"',''),'[',''),']','')
Output:
{EmployeeId:1,
EmployeeName:Maria,
Products:{ProductName:Book},{ProductName:Box}}
If you have any question, please feel free to let me know.
Regards
Echo
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.