?
Solved

Easy SQL date question

Posted on 2008-10-08
2
Medium Priority
?
224 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
[X]
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
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

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ā€¦
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses

801 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