Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Calculate by current month and year

Posted on 2010-01-06
6
Medium Priority
?
313 Views
Last Modified: 2012-05-08
hi there i have this SP :
the problem is that i get the Calculation of the current last year
i need that the Calculation will be on the current year and month

thanks ....
ALTER PROCEDURE dbo.GetTotalCerditFromCurrentMonth
	
AS
	SET NOCOUNT ON 
SELECT sum(CrMoveTasSum) as CerditSum  FROM dbo.CreditMoveDet inner join dbo.CreditMoves on CrMoveMainId=CreRunId
                WHERE DATEPART(month,CreOpenDate) = DATEPART(month, GetDate())
	RETURN

Open in new window

0
Comment
Question by:Tech_Men
  • 3
  • 3
6 Comments
 
LVL 13

Expert Comment

by:zadeveloper
ID: 26190547
try this
ALTER PROCEDURE dbo.GetTotalCerditFromCurrentMonth
	-- I added this optionaal parameter so that you could have more flexability.
	-- iT WILL NOT AFFECT YOUR CURRENT CALLS TO IF, AND WILL WORK AS IT USED TO IF ITS NOT PASSED IN :)
	@WorkingDate datetime = null  
AS 

--DECLARE @WorkingDate datetime
--SET @WorkingDate = GETDATE()

SET NOCOUNT ON  

SELECT 
	sum(CrMoveTasSum) as CerditSum  
FROM 
	dbo.CreditMoveDet 
	inner join dbo.CreditMoves on CrMoveMainId=CreRunId 
WHERE 
	datepart(month,CreOpenDate) = datepart(month, @WorkingDate) 
	and datepart(year,CreOpenDate) = datepart(year, @WorkingDate) 

Open in new window

0
 

Author Comment

by:Tech_Men
ID: 26190593
i there thanks for your help

why i need a datetime parameter u can use an sql func for it
0
 
LVL 13

Expert Comment

by:zadeveloper
ID: 26190609
inclase you want to give a user the flexability of executing the sp based no a previous date. - not nessasary ... thought it may be usefull though :)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Accepted Solution

by:
zadeveloper earned 2000 total points
ID: 26190628
sorry left out the is null check :)
ALTER PROCEDURE dbo.GetTotalCerditFromCurrentMonth
	-- I added this optionaal parameter so that you could have more flexability.
	-- iT WILL NOT AFFECT YOUR CURRENT CALLS TO IF, AND WILL WORK AS IT USED TO IF ITS NOT PASSED IN :)
	@WorkingDate datetime = null  
AS 

--DECLARE @WorkingDate datetime
--SET @WorkingDate = GETDATE()

SET NOCOUNT ON  

if (@WorkingDate is null)
	set @WorkingDate = GETDATE()
	
SELECT 
	sum(CrMoveTasSum) as CerditSum  
FROM 
	dbo.CreditMoveDet 
	inner join dbo.CreditMoves on CrMoveMainId=CreRunId 
WHERE 
	datepart(month,CreOpenDate) = datepart(month, @WorkingDate) 
	and datepart(year,CreOpenDate) = datepart(year, @WorkingDate) 

Open in new window

0
 

Author Comment

by:Tech_Men
ID: 26190661
sorry i dont want this solution i need a solution whitout parameters
0
 

Author Closing Comment

by:Tech_Men
ID: 31673476
i get it
thanks ...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question