Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 date based query

Author  Topic 

hameedf
Starting Member

27 Posts

Posted - 2012-10-24 : 03:40:32
Hello experts !

I need some help again how can i create a query for

life to date,
year to date,
month to date



Hameed

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-10-24 : 03:44:45
Can you please give an example?
It is not very clear what you want...

Best will be to give table structure, sample data and wanted result.


Too old to Rock'n'Roll too young to die.
Go to Top of Page

hameedf
Starting Member

27 Posts

Posted - 2012-10-24 : 03:56:11
Webfred,

Suppose one id in table contain data from 1/1/19000. I need to create a query that sum every day data the previous record make cumulatives. if i run the query to date it sum the data from 1/1/19000 to date on range based not cumulative and showing one figure.
2. Month to date = Suppose october 2012 is the month if irun the query till 23rd october 2012 it cumulate the data on range bases.
3. year to date= reterive records if my date is 7/1/2010 then query acumulate the data from 1/1/2010 to 7/1/2010 on range based.

Sorry my english not good.



Hameed
Go to Top of Page

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2012-10-24 : 03:58:44
DATEDIFF()

http://msdn.microsoft.com/en-us/library/ms189794.aspx

--------------------------
http://connectsql.blogspot.com/
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-10-24 : 04:35:49
quote:
Originally posted by hameedf

Webfred,

Suppose one id in table contain data from 1/1/19000. I need to create a query that sum every day data the previous record make cumulatives. if i run the query to date it sum the data from 1/1/19000 to date on range based not cumulative and showing one figure.
2. Month to date = Suppose october 2012 is the month if irun the query till 23rd october 2012 it cumulate the data on range bases.
3. year to date= reterive records if my date is 7/1/2010 then query acumulate the data from 1/1/2010 to 7/1/2010 on range based.

Sorry my english not good.



Hameed


Hello Hameed,

it isn't a matter of good or bad english to give table structure, sample data and wanted result.

Please try to give table structure, sample data and wanted result.

See here: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Greetings
Fred


Too old to Rock'n'Roll too young to die.
Go to Top of Page
   

- Advertisement -