-2

I want to make a query which will give me the list of not empty data from SQL. I wrote a query but not working. Please help

SELECT * FROM [EmployeePIMSInfo] 
    WHERE [Group] = 'Dhaka' and [SalaryRuleCode] != ('Rule-EXP') and 
    [Status] = 'Active' and Designation = 'Peon' 
    and (EMail != '' or EMail is not null)
3
  • Please show sample data and desired results as formatted text Commented Sep 26, 2023 at 6:37
  • what error you are getting? Commented Sep 26, 2023 at 6:38
  • 1
    You can just use EMail != '' - that implicitly excludes NULL anyway here Commented Sep 26, 2023 at 6:43

1 Answer 1

0

Use and instead of or

SELECT * FROM [EmployeePIMSInfo] 
    WHERE [Group] = 'Dhaka' and [SalaryRuleCode] != ('Rule-EXP') and 
    [Status] = 'Active' and Designation = 'Peon' 
    and EMail != '' and EMail is not null
Sign up to request clarification or add additional context in comments.

3 Comments

and EMail != '' and EMail is not null is redundant, you can just do and EMail != '' as that excludes nulls anyway.
@Charlieface nulls and empty string
Again EMail != '' already excludes nulls also. See eg stackoverflow.com/a/5658472/14868997

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.