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

Skiping empty columns

Status
Not open for further replies.

SQLBeginer

Technical User
Feb 15, 2005
2
US
I have the following table:

ID ITEM1 ITEM2 ITEM3 ITEM4
1 222 333
2 111 333
3 111 444

I need to create another table to be something like this:

ID ITEM1 ITEM2
1 222 333
2 111 333
3 111 444

How can I do this?
Please help!
 
Are there always 2 out of 4 items?

select
id,
coalesce(item1, item2, item3, item4) as item1,
coalesce(item4, item3, item2, item1) as item2
from tab

Dieter
 
A better option would be a more normalized table. Your current table design is considdered very poor table design.
What you want is a simple list.
ID, Item
1, 222
1, 333
2, 111
2, 333
3, 111
3, 444
...

Denny

--Anything is possible. All it takes is a little research. (Me)

[noevil]
(My very old site)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top