User-2082239438 posted
Hi
I have below code . After Union All Insert it is giving above error
IF EXISTS(SELECT TOP 1 EmployeeID FROM dbo.Employee)
begin
INSERT INTO dbo.Employee (EmployeeID,FirstName)
SELECT No_,[First Name]
FROM [Test] AS t0
WHERE t0.No_ not in (Select EmployeeID from dbo.Employee) and t0.No_ is not null and t0.Status = 0
Union All
INSERT INTO dbo.Employee (EmployeeID,FirstName)
SELECT No_,[First Name]
FROM [Test] AS t0
WHERE t0.No_ not in (Select EmployeeID from dbo.Employee) and t0.No_ is not null
END
else
Begin
End
Thanks
You will need to remove the second insert statement after union all. Union All will give the result set from the both the select query & then the result set will get insert into the table.
find the sample below.
IF EXISTS(SELECT TOP 1 EmployeeID FROM dbo.Employee)
begin
INSERT INTO dbo.Employee (EmployeeID,FirstName)
SELECT No_,[First Name]
FROM [Test] AS t0
WHERE t0.No_ not in (Select EmployeeID from dbo.Employee) and t0.No_ is not null and t0.Status = 0
Union All
---INSERT INTO dbo.Employee (EmployeeID,FirstName) ---Remove this Lince
SELECT No_,[First Name]
FROM [Test] AS t0
WHERE t0.No_ not in (Select EmployeeID from dbo.Employee) and t0.No_ is not null
END
--else ---------Removed Un Used Else Statements
--Begin
--End