SQLTeam.com | Weblogs | Forums

Row by Row Insert Query

The Below code works fine for single insert, but I need to do row by row insert starting E.EmpId 101 till the end.

Insert into Emp values (Col1,Col2,Col3,Col4,Col5)

select BarCode -1 as 'RefNumber' from table1 t1 where t1.Col=E.Col
,'Default Value'
,(select isnull(p.JoinDate,t.ReleaseDate) from table2 t2 where t2.Col=E.Col
,(SELECT LEFT(ACCOUNT+'0000000000', 10) from table3 where t3.Col=E.Col
,(select case when Col5 then else)...from table4 where t4.Col=E.Col

from EmpStagging E Where E.EmpId=101

That doesn't look like valid SQL - at least not for SQL Server. What you need to do is figure out how to write a single query that returns the results you want inserted.

Based on what I see - you should be able to just join from EmpStagging to the other tables and return the columns needed.

Jeff's right. Why would you ever want to insert row by row when you don't need to. If you provide DDL and sample data, we could help you