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

Hello, My SQL request looks like

Status
Not open for further replies.

PROPAR

Programmer
Oct 25, 2001
51
FR
Hello,

My SQL request looks like this :

->from Table(Name(varchar), Type(int))

select Name as col1,
case Type when 1 then '1' else '0' end as col2,
case Type when 2 then '1' else '0' end as col3,
case Type when 3 then '1' else '0' end as col4,
case Type when 4 then '1' else '0' end as col5,
case Type when 5 then '1' else '0' end as col6
from Table
where Name='100-724'

The 3 lines result is :
col1 col2 col3 col4 col5 col6
---------------- ---- ---- ---- ---- ----
100-724 0 0 0 0 1
100-724 0 0 1 0 0
100-724 1 0 0 0 0

How can I get col2,col4 & col6 bits on a unique results line ?
i.e :
col1 col2 col3 col4 col5 col6
---------------- ---- ---- ---- ---- ----
100-724 1 0 1 0 1

Thank you for your help.
 
If I'm understanding your question correctly, I think you could just do the following:

select Name as col1,
MIN(case Type when 1 then '1' else '0' end as col2),
MIN(case Type when 2 then '1' else '0' end as col3),
MIN(case Type when 3 then '1' else '0' end as col4),
MIN(case Type when 4 then '1' else '0' end as col5),
MIN(case Type when 5 then '1' else '0' end as col6)
from Table
where Name='100-724'
Group by col1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top