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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trasfer Columns to Raw values 1

Status
Not open for further replies.

MikeBlake

Programmer
Dec 13, 2009
2
0
0
US
I have two tables "Product_Barcode_V1" and "Product_Barcode_V2". I have to write SQL which will tranfer "Product_Barcode_V1" data to "Product_Barcode_V2" table.

Tables structure and data values (Product_Barcode_V1)

ID INS_Code_NJ LIC_Code_NJ INS_Code_TX LIC_Code_TX
1 600-30000 600-28426 NULL 100-4260
2 600-35476 600-36621 100-23903 100-75414
3 600-37176 600-46891 100-23914 100-90963


I want to convert the above table in the following form:
(Product_Barcode_V2)

ID Source Type Barcode
1 NJ INS 600-30000
1 NJ LIC 600-28426
1 TX INS NULL
1 TX LIC 100-4260
2 NJ INS 600-35476
2 NJ LIC 600-36621
2 TX INS 100-23903
2 TX LIC 100-75414
3 NJ INS 600-37176
3 NJ LIC 600-46891
3 TX INS 100-23914
3 TX LIC 100-90963

Can anyone please help me write this Insert SQL for this.. Any help gretly appriciated.

Thanks,
Mike
 
Try
Code:
Insert into Product_Barcode_V2 (ID, Source, Type, Barcode)
select ID, 'NJ' as Source, 'INS' as Type, INS_Code_NJ as Barcode 
UNION ALL 
select ID, 'NJ' as Source, 'LIC' as Type, LIC_Code_NJ as Barcode 
UNION ALL
select ID, 'TX' as Source, 'INS' as Type, INS_Code_TX as Barcode 
UNION ALL 
select ID, 'TX' as Source, 'LIC' as Type, LIC_Code_TX as Barcode ORDER BY 1,2,3
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top