If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Data in same row

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-01-06, 14:15
dollar489 dollar489 is offline
Registered User
 
Join Date: Sep 2002
Posts: 456
Data in same row

Hello guys,

I have a table where data is in this format:

ID Name OS
----------------------------------
10 Paul AIX
10 Paul SOLARIS
10 Paul NT

There is another column (4th) which is used for primary key, now the users want the data something like this:

ID Name AIX SOLARIS NT OS390
--------------------------------------------------------
ID Paul Y Y Y N

Is this possible and if yes, please share the SQL. Thanks.

Paul
Reply With Quote
  #2 (permalink)  
Old 02-01-06, 16:33
Wim Wim is offline
Registered User
 
Join Date: Nov 2004
Posts: 1,279
Code:
select T.ID, T.NAME,
      (CASE WHEN (select count(*) 
                 from table1 
                 where T.ID = table1.ID and
                          tabel1.OS = 'AIX') > 0 
           then 'Y'
           else 'N'
       END) as "AIX",
     .... repeat the above for each and every possible value of "OS" ...
from (select distinct ID, NAME from table) as T
__________________
With kind regards . . . . . SQL Server 2000/2005/2008/2008 R2 Earned beers: 16
Wim
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald Knuth
Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages
Reply With Quote
  #3 (permalink)  
Old 02-02-06, 03:26
dollar489 dollar489 is offline
Registered User
 
Join Date: Sep 2002
Posts: 456
My mistake in the initial post but the data is in MS Access 2000 database. I have posted in some MS Access forums too but nothing much have materialized.
Reply With Quote
  #4 (permalink)  
Old 02-02-06, 03:26
dollar489 dollar489 is offline
Registered User
 
Join Date: Sep 2002
Posts: 456
My mistake in the initial post but the data is in MS Access 2000 database. I have posted in some MS Access forums too but nothing much have materialized.
Reply With Quote
  #5 (permalink)  
Old 02-02-06, 10:11
Wim Wim is offline
Registered User
 
Join Date: Nov 2004
Posts: 1,279
You will have to use IIF() instead of CASE.
__________________
With kind regards . . . . . SQL Server 2000/2005/2008/2008 R2 Earned beers: 16
Wim
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald Knuth
Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages
Reply With Quote
  #6 (permalink)  
Old 02-02-06, 10:16
dollar489 dollar489 is offline
Registered User
 
Join Date: Sep 2002
Posts: 456
Yes, I used the IIF statements and it worked. Thanks!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On