Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 12th, 2006, 06:34 PM
Registered User
 
Join Date: Aug 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default T-SQL Code to get last 6 months

Hi there,

I am trying to get the last 6 months of data from a table in SQL Server 2005. Does any body out there know how to write this code to accomplish this?

Thanks in advance,

Midway

Reply With Quote
  #2 (permalink)  
Old October 15th, 2006, 08:59 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Hudson, MA, USA.
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

The DATEADD function allows you to compute a date that is 6 months ago:
Code:
    DATEADD(m, -6, current_timestamp)
use this to compare your date column:
Code:
    SELECT *
      FROM yourtable
     WHERE yourdatecolumn > DATEADD(m, -6, current_timestamp);
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
display all dates within months sanjeev jha Classic ASP Basics 1 June 6th, 2008 12:46 PM
Sql Query to generate months and year arul1984 SQL Server 2000 8 July 23rd, 2007 04:42 PM
Query Help - Display numbers from two Months rkellogg Access 2 September 27th, 2006 08:51 AM
Years to Months Conversion mahajanvit ASP.NET 2.0 Basics 2 September 25th, 2006 11:43 PM
Find months difference tsimsha Classic ASP Databases 4 February 14th, 2005 08:36 PM



All times are GMT -4. The time now is 08:01 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.