Welcome to the SSC 😛
While you post the problems please the DDL statements of Tables, Insert data and desired output so that we can help out you guys quickly.............
Here is the solution of your problem that you posted:
Create table drugs
(
name varchar(20),
Dosage varchar(20),
PackSize int
)
GO
INSERT INTO Drugs
SELECT 'aspirin', '75mg',10
UNION ALL
SELECT 'aspirin', '75mg',20
UNION ALL
SELECT 'aspirin', '150mg',10
UNION ALL
SELECT 'aspirin', '150mg',20
UNION ALL
SELECT 'aspirin', '300mg',10
union all
SELECT 'aspirin', '300mg',20
union all
SELECT 'aspirin', '300mg',30
GO
Here is the script that gives you desired output:
SELECT
d.name,
d.dosage,
MIN(CASE WHEN PackSize = 10 THEN 'x' ELSE 'o' END) Packsize10,
MIN(CASE WHEN packsize =20 THEN 'x' ELSE 'o' END) Packsize20,
MIN(CASE WHEN packsize =30 THEN 'x' ELSE 'o' END) Packsize30
FROM drugs d
GROUP BY d.name, d.dosage, d.PackSize
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/