Azure SQL Database
An Azure relational database service.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
I want to achive these result set into Temp table.Pleas suggest.
SELECT ID, Reference
FROM Emp
WHERE ID NOT IN (SELECT tID FROM Dept)
UNION
SELECT O.ID, ''
FROM Emp P, Dept O
WHERE P.tID = O.ID
ORDER BY 1
An Azure relational database service.
Answer accepted by question author
Try the following:
SELECT t.* INTO #TempTable1
FROM
(
SELECT ID, Reference
FROM Emp
WHERE ID NOT IN (SELECT tID FROM Dept)
UNION
SELECT O.ID, ''
FROM Emp P, Dept O
WHERE P.tID = O.ID
ORDER BY 1
) t
SELECT * FROM #TempTable1
DROP TABLE IF EXISTS #TempTable1