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 2000 Forums
 Transact-SQL (2000)
 Month and Year as parameter with date field?

Author  Topic 

chriskhan2000
Aged Yak Warrior

544 Posts

Posted - 2005-06-17 : 09:59:05
I have a SP that I want to use just the Month and Year as parameter and then default the end of month date base on the year and month. Anyone know how I would go about doing this. We have posting dates that I want to use as my search criteria and those are posted by month end.

Example:

Month end is 1/31/2005, the parameter I set is "1" for Month and then "2005" for Year. Then default Day to month end date so that the user does not need to enter it.


Here's my query:

CREATE PROCEDURE CW_MONTHEND_REPORT
@DATE AS SMALLDATETIME
AS
SELECT ID, POSTING_DATE, CLOSING_DATE
FROM WORK_IN_PROCESS
WHERE POSTING_DATE = @DATE


Here's an attempt, but I don't know how to set my @DAY parameter to default to month end base on year and month.

CREATE PROCEDURE CW_MONTHEND_REPORT

@MONTH AS VARCHAR(2),
@DAY AS VARCHAR(2),
@YEAR AS VARCHAR(4)

AS

SELECT ID, POSTING_DATE, CLOSING_DATE
FROM WORK_IN_PROCESS
WHERE POSTING_DATE = @MONTH + '/' + @DAY + '/' + @YEAR

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-06-17 : 10:11:50
Refer this
http://weblogs.sqlteam.com/brettk/archive/2005/06/02/5528.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

chriskhan2000
Aged Yak Warrior

544 Posts

Posted - 2005-06-17 : 10:21:54
Thanks I got it to work now.

I just set the date for Month and Year as parameter with the Date format.

Example:

CREATE PROCEDURE CW_MONTHEND_REPORT

@MONTH AS VARCHAR(2),
@YEAR AS VARCHAR(4)

AS

SELECT ID, POSTING_DATE, CLOSING_DATE
FROM WORK_IN_PROCESS
WHERE DATENAME(MONTH, POSTING_DATE) = @MONTH
AND YEAR(POSTING_DATE) = @YEAR
Go to Top of Page
   

- Advertisement -