Click here to Skip to main content
15,887,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
suppose I have the following code:
SQL
select employer_id
from employer_tb

I want this code to give me a true/false value.
false if employer_id is empty, otherwise it should give a true value.
someone please show me how?
Posted
v2
Comments
Do you want to check for one particular employer_id, whether it exists in the table or not, right ?
Or what you exactly want to show ?
faisal23 8-Nov-12 5:39am    
I think you have to check whether particular id is present or not. In this condition use
select * from employer_tb where emplyer_id=......

you can do this with case statement:

SQL
SELECT   Employer =
      CASE employer_id
         WHEN '' THEN 'true'
         ELSE 'false'
      END
from employer_tb


this assums that data is '' and not null.
 
Share this answer
 
Comments
Baji Jabbar 8-Nov-12 6:00am    
Good call!
I guess OP wants false, when employer_id is empty.
But you have written as true.
Om Prakash Pant 8-Nov-12 7:03am    
yes, it has to be the other way
Then please change your code.
Thanks...
You will have to provide the parameter value for @employer_id
SQL
IF (select count(*) from   employer_tb   where employer_id = @employer_id)=1
BEGIN    PRINT 'true' END
ELSE 
BEGIN    PRINT 'false' END


If in your logic an employee id can appear more than once, modify the code above as:
(select count(*) from   employer_tb   where employer_id = @employer_id)>=1


Hope this helps
 
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