SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 date based query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

hameedf
Starting Member

Pakistan
27 Posts

Posted - 10/24/2012 :  03:40:32  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

Germany
8766 Posts

Posted - 10/24/2012 :  03:44:45  Show Profile  Visit webfred's Homepage  Reply with Quote
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

Pakistan
27 Posts

Posted - 10/24/2012 :  03:56:11  Show Profile  Reply with Quote
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

Pakistan
885 Posts

Posted - 10/24/2012 :  03:58:44  Show Profile  Visit lionofdezert's Homepage  Send lionofdezert a Yahoo! Message  Reply with Quote
DATEDIFF()

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

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

webfred
Flowing Fount of Yak Knowledge

Germany
8766 Posts

Posted - 10/24/2012 :  04:35:49  Show Profile  Visit webfred's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.17 seconds. Powered By: Snitz Forums 2000