We help IT Professionals succeed at work.

SQL Statement for Expired Records

nauman_ahmed
nauman_ahmed asked
on
Medium Priority
344 Views
Last Modified: 2008-03-10
I have a field EXPIRATION_DATE in table DOMAIN. This field can be null. I would like to select records in this table based on EXPIRATION_DATE field so that the SQL query return the records where EXPIRATION_DATE is null and for the records where expiration date is not null it only returns the record when GetDate() < EXPIRATION_DATE. Please help me in writing this query.

Thanks,
Nauman.
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2011
Commented:
select * from domain
where expiration_date is null
or expiration_ date > getdate()

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
CERTIFIED EXPERT
Top Expert 2010
Commented:
Hi nauman,

SELECT *
FROM DOMAIN
WHERE (EXPIRATION_DATE IS NULL) OR (EXPIRATION_DATE > GETDATE())

Regards,

Patrick

Author

Commented:
I totally missed the OR clause. Thanks for the quick reply experts :)

-Nauman.
CERTIFIED EXPERT
Top Expert 2010

Commented:
Glad to help :)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.