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

insert duplicate records for each flag 1

Status
Not open for further replies.

markbrum

Technical User
Mar 10, 2003
46
0
0
GB
Hi,

I have a table like this:-

name a b c d
john 0 0 5 0
dave 2 4 0 5
mark 0 9 0 8

i would like one line for each name where the value isn't zero i.e.

name item value
john c 5
dave a 2
dave b 4
dave d 5
mark b 9
mark d 8

could anyone please point me in the right direction?

thanks a lot.

mark.
 
Something like this ?
SELECT name, 'a' AS item, a AS value FROM yourTable WHERE a <> 0
UNION SELECT name, 'b', b FROM yourTable WHERE b <> 0
UNION SELECT name, 'c', c FROM yourTable WHERE c <> 0
UNION SELECT name, 'd', d FROM yourTable WHERE d <> 0

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
that worked great, thanks very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top