Skip to main content
Added convert to 4 MAX lines
Source Link
Aaron Bertrand
  • 181.5k
  • 28
  • 402
  • 619

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;
SELECT sip_RECno, 
    user1 = MAX(CASE WHEN ONAY_ID = 1 THEN ONAY END),
    user2 = MAX(CASE WHEN ONAY_ID = 2 THEN ONAY END),
    user3 = MAX(CASE WHEN ONAY_ID = 3 THEN ONAY END),
    user4 = MAX(CASE WHEN ONAY_ID = 4 THEN ONAY END)
FROM dbo.tablename
WHERE sup_RECno = 1
GROUP BY sip_RECno;

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;
edited body
Source Link
Aaron Bertrand
  • 181.5k
  • 28
  • 402
  • 619
SELECT sip_RECno, 
    user1 = MAX(CASE WHEN ONAY_ID = 1 THEN ONAY END),
    user2 = MAX(CASE WHEN ONAY_ID = 2 THEN ONAY END),
    user3 = MAX(CASE WHEN ONAY_ID = 3 THEN ONAY END),
    user4 = MAX(CASE WHEN ONAY_ID = 4 THEN ONAY END)
FROM dbo.tablename
GROUP BY sip_RECno
WHERE sup_RECno = 1;1
GROUP BY sip_RECno;
SELECT sip_RECno, 
    user1 = MAX(CASE WHEN ONAY_ID = 1 THEN ONAY END),
    user2 = MAX(CASE WHEN ONAY_ID = 2 THEN ONAY END),
    user3 = MAX(CASE WHEN ONAY_ID = 3 THEN ONAY END),
    user4 = MAX(CASE WHEN ONAY_ID = 4 THEN ONAY END)
FROM dbo.tablename
GROUP BY sip_RECno
WHERE sup_RECno = 1;
SELECT sip_RECno, 
    user1 = MAX(CASE WHEN ONAY_ID = 1 THEN ONAY END),
    user2 = MAX(CASE WHEN ONAY_ID = 2 THEN ONAY END),
    user3 = MAX(CASE WHEN ONAY_ID = 3 THEN ONAY END),
    user4 = MAX(CASE WHEN ONAY_ID = 4 THEN ONAY END)
FROM dbo.tablename
WHERE sup_RECno = 1
GROUP BY sip_RECno;
Source Link
Aaron Bertrand
  • 181.5k
  • 28
  • 402
  • 619

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