Click here to Skip to main content
14,699,613 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Updated 28-Feb-14 1:16am
Maciej Los 28-Feb-14 6:30am
Member 10517120 1-Mar-14 0:31am

im very new to sql jus 3 moonths old

1 solution

Please, read my comment to the question.

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

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