ssurekha2000 (7/16/2013)
i need to insert records from table1 to table 2out of 15 columns from table1 i need to insert 6 columns to table 2
but
if i use
insert into table2
select col1,col4,col5,col8,col10, @sqno from table1 where custid=11
if table1 has 30 records all will be inserted at once
but i need to have a loop such that
row1 will, be inserted , than 2 and so on till 30
if its possible to do without cursor it will be more good
Can you explain why you would want to do that? Presumably something to do with @sqno? Most people on this forum would feel dirty writing such a thing 🙂
But if RBAR processing is really what you want, a CURSOR is as good a way as any.
Your INSERT syntax is deficient though - you should list the columns you are inserting into:
insert table2
(col1
,col4
,col5
,col8
,col10
,sqno
)
select col1
,col4
,col5
,col8
,col10
,@sqno
from table1
where custid = 11
If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.