Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
select BookTitle,Library_Department_ID,SectorID,sum(NoofCopies) from tbl_bookmst where Status= 1 group by BookTitle,Library_Department_ID,SectorID



this is wt my query is .



I'm having one more column(bit) named IsReference which is 1 for Referencebook

and 0 for Issuebook

now i need to Convert this row to column With the name reference and Issue

How i need to Write the query
Posted
Updated 28-Feb-14 0:16am
v2
Comments
Maciej Los 28-Feb-14 6:30am    
Member 10517120 1-Mar-14 0:31am    
ok

im very new to sql jus 3 moonths old

1 solution

Please, read my comment to the question.

SQL
SELECT BookTitle, Library_Department_ID, SectorID, [Reference], [Issue]
FROM (
    SELECT BookTitle, Library_Department_ID, SectorID, NoofCopies, CASE WHEN [Status] = 1 THEN 'Reference' ELSE 'Issue' END
    FROM tbl_bookmst
    WHERE Status= 1 
) AS DT
PIVOT(SUM(NoofCopies) FOR [Status] IN([Reference], [Issue])) AS PT
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900