Solved

Easy SQL date question

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

809 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