-2

I have a table name TABLE1 in which I have a column YEAR where I an storing the year information like 1990 , 2000 ,2001 etc. I have another table TABLE2 in which I have the Year column and other columns as well.

Now I want to select each year from the TABLE1 and then insert some record into the TABLE2 like...

Year     Information
1990     abc
1990     lmn
1990     xyz
2000     abc
2000     lmn 
2000     xyz

How can I get this I do not know how I will use the while loop or how I will get the each row from select statement and then pass it to the insert statement.

geekonaut
  • 5,714
  • 2
  • 28
  • 30
Nosheen Javed
  • 175
  • 1
  • 5
  • 21

1 Answers1

0

You can do:

INSERT INTO dbo.Table2 ( Year, OtherColumn )

SELECT      Year
            OtherColumn

FROM        dbo.Table1

Of course, you can add whatever WHERE or GROUP BY, etc. clauses to suit your needs.

Rowland Shaw
  • 37,700
  • 14
  • 97
  • 166