Solved

isnull in where clause

Posted on 2010-11-30
6
261 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now