I am passing datatable as input parameter to a stored procedure. I have created custom type for it. Here is my stored procedure:
INSERT INTO Employee
([Name],[Lname],[Code])
SELECT [Name],[Lname],@Code
FROM @tblEmp A
WHERE NOT EXISTS (SELECT 1
FROM Employee B
inner join Contactdetail c
on cid = B.cid
WHERE B.[Name] = A.[Name]
AND B.[Lname] = A.[Lname]
AND C.[mobno] = A.[mobno])
Here I fetching record from datatable and inserting into Employee table. Datatable contain Name,Lname and mobileno. I want to check combination of Name,Lname and mobileno.If combination of it present in Employee table,pls don't insert record([Name], [Lname], @Code ) in Employee.Else Insert.After inserting record from Employee,I want id of all inserted record.Scope_identity give last identity of table.I want all id,which are newly inserted into table because in same sp,I want to do further processing.
So I modified my code.Now I am using like this
DECLARE @InsertedIDs table(EmployeeID int);
INSERT INTO Employee
([Name],[Lname],[Code])
OUTPUT INSERTED.ID
INTO @InsertedIDs
SELECT [Name],[Lname],@Code
FROM @tblEmp A
WHERE NOT EXISTS (SELECT 1
FROM Employee B
inner join Contactdetail c
on cid = B.cid
WHERE B.[Name] = A.[Name]
AND B.[Lname] = A.[Lname]
AND C.[mobno] = A.[mobno])
It store value of id into another table.I want to add id to that datatable or another table with all record from datatable.How to do that?