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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to make procedure to calculate data between

Author  Topic 

nikoz
Yak Posting Veteran

63 Posts

Posted - 2013-12-16 : 08:41:42
How to make procedure to calculate data between month ?
I have this but i don't know what to do with that :(

between dbo.fPA_FirstDayOfTheMonth(dateAdd(month, -1, dbo.fPA_RemovingTime(getDate()))) and
dbo.fPA_LastDayOfTheMonth(dateAdd(month, -1, dbo.fPA_RemovingTime(getDate())))

djj55
Constraint Violating Yak Guru

352 Posts

Posted - 2013-12-16 : 08:54:02
[code]SELECT *
FROM MyTable
WHERE MyDate BETWEEN DATEADD(month,DATEDIFF(month, 0,GETDATE()),0) AND
DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0))[/code]
Analyze this code and maybe that will help you.

djj
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-12-16 : 10:20:55
see
http://visakhm.blogspot.in/2012/12/different-ways-to-implement-date-range.html
Its not recommended to apply any functions over date fields in WHERE as it would make it Non Sargable and will ignore any indexes if present on the columns.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

ScottPletcher
Aged Yak Warrior

550 Posts

Posted - 2013-12-16 : 12:14:15
[code]

WHERE
date_column >= DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) - 1, 0) AND
date_column < DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0)

[/code]
Go to Top of Page
   

- Advertisement -