Solved

isnull in where clause

Posted on 2010-11-30
6
264 Views
Last Modified: 2012-05-10
I want to put the following code in my query where statement: isnull(criteria,'1=1').

the critieria will either be something like "Age < 18", "Age > 18", etc,  or NULL. I would love for there to be a SQL eval statement but there is not.  also i want to stay away from dynamic SQL.......is thre anything that i can do here or do i have to go to dynamic SQL?
0
Comment
Question by:DB_Fury
  • 3
  • 3
6 Comments
 
LVL 16

Expert Comment

by:EvilPostIt
ID: 34240258
you will need to use IS NULL not ISNULL.

ISNULL is a function that replaces a NULL values with a user specified one.
0
 
LVL 1

Author Comment

by:DB_Fury
ID: 34240272
yeah thats what i want becuase it the criteria field is null in the database i just want to put something that will always be true there so there isjust just a and with a blank in the syntax
0
 
LVL 16

Accepted Solution

by:
EvilPostIt earned 500 total points
ID: 34240312
WHERE ISNULL(AGE,0)<18 AND ISNULL(AGE,0)>18
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 1

Author Comment

by:DB_Fury
ID: 34240347
i cant put anything static becuase it could be null, it could be Age > 20. so hardcoding it wont work.  i wish there was a eval funcation
0
 
LVL 16

Expert Comment

by:EvilPostIt
ID: 34240371
If the age is 20 is wont be nulland will not therefore be replaced with 0. Only in the event of a null value will it be replaced.
0
 
LVL 1

Author Closing Comment

by:DB_Fury
ID: 34240519
I was confused at first but now i understand.  thanks very much
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

832 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