Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Friends,

In sql I have 2 record in my table. I want return null if my value is not available. But I am getting data.

Could anyone help on this?

Thanks.

What I have tried:

I tried this.

FROM Log_Interface_Service_Status_Bimbo
WHERE LISS_Date = CONVERT(DATE,GETDATE())
AND LISS_Service_Name IN ('RetailerHierarchyWorkerServiceV1','ProductWorkerServiceV1','PriceWorkerServiceV1')
AND LISS_Status = 'Completed'

Here I want return null, because PriceWorkerServiceV1 is not available in my table. So I want null only. How can I build query
Posted
Updated 27-Dec-22 23:42pm

1 solution

Hello,

If you look closely, you where clause would tell you why you're getting records even when "one" of the values in service name do not exist.
The Where ** IN clause lets you choose between different values and return a record that matches any one of them.
SQL IN Operator[^]

If you want to return records only when your condition is met, use the Where clause instead of the Where ** IN clause.
 
Share this answer
 
v2
Comments
Gunasekaran Krishnamoorthy 28-Dec-22 5:50am    
But in where condition how can I use these 3 values ?

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