Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert 1 field into multiple fields 1

Status
Not open for further replies.

puter55

Programmer
Apr 11, 2003
16
US
Table1 contains a integer field called type. It contains either a 1,2,3,4, or 5.

I need to insert into table2 either a 1 or 0 into 5 different fields. So if type contains 3 I would need to insert
field1 0
field2 0
field3 1
field4 0
field5 0

Thanks
 
Hi,

How about...

Code:
insert into [Table2] (field1, field2, field3, field4, field5)
select 
case when types = 1 then 1 else 0 end,
case when types = 2 then 1 else 0 end,
case when types = 3 then 1 else 0 end,
case when types = 4 then 1 else 0 end,
case when types = 5 then 1 else 0 end
from [Table1]

Ryan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top