johnny
johnny

Reputation: 29

Query to validate and return true or false

Hi could anyone help on the below please

If I have a table where the values are as below

emp_id          emp Name 
 100              john 
 200              Jenny
 300              jack
 400              san

I would like to run a query where emp_id and name are already declared and it should return true when the value is correct Eg:

emp_id : 100 
Emp_name : john

is the value declared then the query should return true else false.

Upvotes: 1

Views: 657

Answers (1)

Satwik Nadkarny
Satwik Nadkarny

Reputation: 5135

This should suffice :

SELECT  CASE
            WHEN COUNT(emp_id) > 0 THEN 'TRUE'
            ELSE 'FALSE'
        END
FROM    #tab
WHERE   emp_id = @empID
AND     empName = @empName

@empID and @empName are the parameters for emp_id and empName respectively.

You can see this here ->

http://sqlfiddle.com/#!6/126ce/1 (where its returns TRUE based on the values)

http://sqlfiddle.com/#!6/126ce/2 (where its returns FALSE based on the values)

Upvotes: 2

Related Questions