[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Using CASE in a where clause

Posted on 2006-06-02
7
Medium Priority
?
267 Views
Last Modified: 2012-08-14
Is this possible?

Here is the where clause in my query:

a_gatetxn.trailerid = a_yardcheck.trailerid

let's say that a_gatetxn.trailerid = '' or is null...if that were the case, then it would not have a matching trailerid in the a_yardcheck table (a_yardcheck.trailerid). Is it possible to say when the a_Gatetxn.trailerid is null or is blank, don't use this particular line in the where clause?

Thanks
0
Comment
Question by:ONYX
7 Comments
 
LVL 23

Accepted Solution

by:
Saqib Khan earned 100 total points
ID: 16821013
You can not use Case statement with Where Clause.
0
 
LVL 13

Expert Comment

by:Atlanta_Mike
ID: 16821296
The trick is in your join.


SELECT *
FROM a_gatetxn
LEFT JOIN a_yardcheck
ON a_gatetxn.trailerid = a_yardcheck.trailerid
WHERE a_yardcheck.trailerid IS NULL
0
 
LVL 28

Expert Comment

by:imran_fast
ID: 16822251
where
case when a_gatetxn.trailerid is null then a_yardcheck.trailerid
        when a_gatetxn.trailerid='' then a_yardcheck.trailerid
        else a_gatetxn.trailerid end =  a_yardcheck.trailerid
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 50

Expert Comment

by:Lowfatspread
ID: 16822516
SELECT *
FROM a_gatetxn
LEFT JOIN a_yardcheck
ON a_gatetxn.trailerid = a_yardcheck.trailerid
--WHERE a_yardcheck.trailerid IS NULL

i'm not clear if you actually need the is null check in Mike's example...


0
 
LVL 4

Expert Comment

by:indu_mk
ID: 16822870
WHERE a_gatetxn.trailerid =
CASE a_gatetxn.trailerid WHEN null THEN a_gatetxn.trailerid
WHEN "" THEN a_gatetxn.trailerid
ELSE a_yardcheck.trailerid END
0
 
LVL 13

Expert Comment

by:Atlanta_Mike
ID: 16833088
If he is trying to find those that don't have a match then he does. It's kinf of hard to tell if that's what he isa after.
0
 
LVL 13

Expert Comment

by:Atlanta_Mike
ID: 17021866
Ummm... not only is it possible to use a case statement ... but it is done. It's just not needed in this example?
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question