2

I have a table as shown below.My question is:How can I convert columns into rows?BTW,I'm using Microsoft SQL Server 2005.

my input Data

  ONAY_ID  sip_RECno    KULLANICI       ONAY
   1           1         user1          true
   2           1         user2          true
   3           1         user3          false
   4           1         user4          true

Output would be

 sip_RECno  user1     user2    user3     user4       

  1          true     true    false    true          
3
  • 1
    What database/version are you working with? Based on previous questions, I'd assume SQL Server but you've had titles with 2000 and 2005 so version will matter
    – billinkc
    Commented Sep 12, 2011 at 14:09
  • I've updated the tags to include sql-server - can you please get in the habit of being specific (including version) so that folks using Oracle, DB2 etc. don't try to solve your problem with inappropriate solutions? Commented Sep 13, 2011 at 13:34
  • @Aaron Bertrand-I've updated my question.
    – Cell-o
    Commented Sep 13, 2011 at 14:26

1 Answer 1

1

EDIT for new data type revelation...

SELECT sip_RECno, 
    user1 = MAX(CASE WHEN ONAY_ID = 1 THEN CONVERT(TINYINT, ONAY) END),
    user2 = MAX(CASE WHEN ONAY_ID = 2 THEN CONVERT(TINYINT, ONAY) END),
    user3 = MAX(CASE WHEN ONAY_ID = 3 THEN CONVERT(TINYINT, ONAY) END),
    user4 = MAX(CASE WHEN ONAY_ID = 4 THEN CONVERT(TINYINT, ONAY) END)
FROM dbo.tablename
WHERE sup_RECno = 1
GROUP BY sip_RECno;
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.