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
 Development Tools
 Reporting Services Development
 Parameter Help

Author  Topic 

chriskhan2000
Aged Yak Warrior

544 Posts

Posted - 2005-04-26 : 14:52:17
I'm not clear on how to do this, but I want to have a parameter that has the months and another parameter with the years. The months will be drop down, while the years the user can enter manually. Also the months will display end of month on it like '01/31/2004'

In my query, I set the parameter as date, but how would I set it so that I can have the date search by month and year?

Example of what I have:

CREATE PROC SP_CUSTOMER
@DATE AS SMALLDATETIME
AS
SELECT ID, CUSTOMER, ADDRESS
FROM CUSTOMER
WHERE CUSTOMER.CREATE_DATE = @DATE

What I'm hoping to achieve:

CREATE PROC SP_CUSTOMER
@MONTH AS SMALLDATETIME,
@YEAR AS SMALLDATETIME
AS
SELECT ID, CUSTOMER, ADDRESS
FROM CUSTOMER
WHERE CUSTOMER.CREATE_DATE = @MONTH
AND CUSTOMER.CREATE_DATE = @YEAR

Once they picked let say March, 2005. It will be like 03/31/2005.

Any ideas?

mfemenel
Professor Frink

1421 Posts

Posted - 2005-04-26 : 15:24:22
Try this:
CREATE PROC SP_CUSTOMER
@MONTH AS tinyint,
@YEAR AS smallint
AS
SELECT ID, CUSTOMER, ADDRESS
FROM CUSTOMER
WHERE month(CUSTOMER.CREATE_DATE) = @MONTH
AND year(CUSTOMER.CREATE_DATE) = @YEAR

Mike
"oh, that monkey is going to pay"
Go to Top of Page
   

- Advertisement -