Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

isnull in where clause

Posted on 2010-11-30
6
Medium Priority
?
272 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 2000 total points
ID: 34240312
WHERE ISNULL(AGE,0)<18 AND ISNULL(AGE,0)>18
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
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…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

824 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