| Author |
Topic |
|
vikoch
Starting Member
6 Posts |
Posted - 2010-03-15 : 13:22:07
|
| Hello,I need help please!I have a simple SQl- select ID from order_meet where begin_date between '09/01/2009' and getdate())But, I need to modify this query to get all IDs between September last year and today month and year.Is anyone can help me with this?Thank you.Irina |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-03-15 : 13:29:59
|
| [code]select ID from order_meet where begin_date between dateadd(mm,8,dateadd(yy,dateadd(yy,0,getdate())-1,0)) and getdate())[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
vikoch
Starting Member
6 Posts |
Posted - 2010-03-15 : 13:56:27
|
| Thank you for reply.When I used your date format I got this message - "Argument data type datetime is invalid for argument 2 of dateadd function.Please keep in mind - I need to get all IDs between September last year, and today month and year (only). - I don't need today dateThank youIrina |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-03-15 : 13:59:25
|
then it should beselect ID from order_meet where begin_date >= dateadd(mm,8,datediff(yy,dateadd(yy,0,getdate())-1,0)) and begin_date <dateadd(mm,datediff(mm,0,getdate()),0) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
vikoch
Starting Member
6 Posts |
Posted - 2010-03-15 : 14:27:18
|
| Now this query selects all IDs with all begin_dates (for 2006, 2007, 2008) But, I need only between last year September and today month and year (not exact day). Is it possible? Thanks in advanceIrina |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-03-16 : 00:08:56
|
| [code]select ID from order_meet where begin_date >= dateadd(mm,8,dateadd(yy,datediff(yy,0,getdate())-1,0)) and begin_date <dateadd(mm,datediff(mm,0,getdate()),0)[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
vikoch
Starting Member
6 Posts |
Posted - 2010-03-16 : 15:58:07
|
| Thank you for your reply. But, this query is selecting all IDs with begin_date between last year September and today date. And I need all IDs with begin_date between last year September and until end of the current month and current year.I am sorry to be pain...Irina |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-03-17 : 01:19:22
|
hello first check and then get backselect ID from order_meet where begin_date >= dateadd(mm,8,dateadd(yy,datediff(yy,0,getdate())-1,0)) and begin_date <dateadd(mm,datediff(mm,0,getdate()),0) it will give data b/w last Sept to start of current month------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
vikoch
Starting Member
6 Posts |
Posted - 2010-03-17 : 11:29:10
|
| I need date b/w last Sept to end of current monthThank youIrina |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-03-17 : 11:35:49
|
the tweak it accordingly. select ID from order_meet where begin_date >= dateadd(mm,8,dateadd(yy,datediff(yy,0,getdate())-1,0)) and begin_date <dateadd(mm,datediff(mm,0,getdate())+1,0) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
vikoch
Starting Member
6 Posts |
Posted - 2010-03-17 : 13:48:16
|
| Thank you very much for your help. It works!Irina |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-03-17 : 13:58:04
|
| welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|