Solved

Easy SQL date question

Posted on 2008-10-08
2
216 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 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
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
Comment Utility
That worked.  Thanks!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Via a live example, show how to take different types of Oracle backups using RMAN.

743 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

17 Experts available now in Live!

Get 1:1 Help Now