Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 326
  • Last Modified:

SQL Statement for Expired Records

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.
0
nauman_ahmed
Asked:
nauman_ahmed
  • 2
2 Solutions
 
LowfatspreadCommented:
select * from domain
where expiration_date is null
or expiration_ date > getdate()
0
 
Patrick MatthewsCommented:
Hi nauman,

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

Regards,

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

-Nauman.
0
 
Patrick MatthewsCommented:
Glad to help :)
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now