Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Easy SQL date question

Posted on 2008-10-08
2
221 Views
Last Modified: 2013-12-07
I am writing a select statement and I would like to show a 1 if a date is in the past and 0 if it is today or in the future.  I'll send up summing that field to come up with the number of records that have a date that is in the past.  This is what I have so far.
SELECT DateField, NameField
FROM MasterTable
WHERE NameField = @Variable
GROUP BY NameField

Open in new window

0
Comment
Question by:ryanvb83
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 22669597
this should do:
SELECT DateField, NameField, CASE WHEN DateField < getdate() then 1 ELSE 0 END past_date
FROM MasterTable
WHERE NameField = @Variable

Open in new window

0
 

Author Closing Comment

by:ryanvb83
ID: 31504258
That worked.  Thanks!
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

In this article I will describe the Backup & Restore 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.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

861 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