Click here to Skip to main content
15,894,180 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Want to Check the condition for BE_BookIssuestatus='A' using count


my query as follows


SQL
SELECT CASE WHEN Count(BE_BookIssuestatus IN('A')) > 0 THEN 'Available' ELSE 'Not Available' END BookStatus from BookEntity_Master


It returns Available When there is BE_BookIsseStatus not equal to 'A' in table,Any Suggestion for this to obtain 'Not Available' when there is no BookIsseStatus 'A'
Posted
Updated 27-Jan-14 23:23pm
v2

change into (use of ISNULL)

SQL
SELECT CASE WHEN ISNULL(Count(BE_BookIssuestatus IN('A')),0) > 0 THEN 'Available' ELSE 'Not Available' END BookStatus from BookEntity_Master
 
Share this answer
 
Hi, I woul sugest doing it with a subquery.
I will assume that there is some sort of ID column.
I don't know if, in this case, MS SQL SERVER is that different from MySQL, but here's a hint.

SELECT CASE ISNULL(A.QT, 0) WHEN 0 THEN 'Not Available' ELSE 'Available' END AS BookStatus FROM BookEntity_Master
LEFT OUTER JOIN (SELECT ID, Count(*) AS QT FROM BookEntity_Master WHERE BE_BookIssuestatus IN('A') GROUP BY ID) AS A
ON A.ID = BookEntity_Master.ID
 
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