Click here to Skip to main content
15,886,071 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table consist of a column 'Marks'. In that marks I've to check whether it is greater than 50 or not. If it is 50 its pass else fail, for this I wrote a query as

SQL
SELECT MARKS,

              CASE WHEN MARKS >= 50 THEN 'PASS'

              ELSE 'FAIL'

              END AS STATUS

              FROM TABLENAME


here I can get the expected result, but the problem is I need to give a parameter as, if I give 0 it shold display only the fail results, and if I give 1 should show only pass, if 2, both fail and pass.........how is it possible can anyone help
Posted
Updated 14-Mar-12 19:13pm
v2
Comments
abdul samathu 15-Mar-12 2:34am    
I need to use this in ssrs

Here is the code:

SQL
DECLARE @ParamVal int
SET @ParamVal = 2

SELECT
CASE @ParamVal
WHEN 0 THEN 
   SELECT MARKS,
   CASE WHEN MARKS < 50 THEN 'FAIL'
   END AS STATUS
WHEN 1 THEN 
   SELECT MARKS,
   CASE WHEN MARKS >= 50 THEN 'PASS'
   END AS STATUS
   FROM TABLENAME
WHEN 2 THEN 
   SELECT MARKS,
   CASE WHEN MARKS >= 50 THEN 'PASS'
   ELSE 'FAIL'
   END AS STATUS
   FROM TABLENAME
 
Share this answer
 
Comments
abdul samathu 15-Mar-12 1:31am    
thanks ganesan, but it shows error,like incorrect syntax near Select statement
Below query should work fine

SQL
DECLARE @Param AS BIT = 1 -- Parameter for PASS/FAIL selection

 SELECT MARKS,
    CASE WHEN MARKS >= 50 THEN 'PASS'
    ELSE 'FAIL'
    END AS STATUS
FROM TABLENAME
WHERE (@Param = 1 AND MARKS >= 50) -- Pass results
OR (@Param = 0 AND MARKS < 50) -- Fail results
OR @Param IS NULL -- All results
 
Share this answer
 
Comments
abdul samathu 15-Mar-12 2:06am    
thanks stalin, how can I use this in ssrs

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