Advertisement

05.28.2008 at 08:58AM PDT, ID: 23438551
[x]
Attachment Details

Problem with SET variable statement in Stored Proc

Asked by GeniusSteals in SQL Server 2005

Tags: Microsoft, SQL Server, 2005

Hi again..today's problem comes from trying to assign a couple of variables based on the value of another variable. In this instance, the variable @RetailWeek is passed to the procedure which should then use this to work out the MinDate and MaxDate for that week referenced in a table.

I see lots of code about but not sure where I am meant to put it in respect of the ALTER PROCEDURE statement. When I try to execute the SP I get the error message:
Procedure or Function 'proc_Update_OP_Single_Week' expects parameter '@MinDate', which was not supplied.

I'll add that I have put the SET statements before AS, after AS (as they are now) and in the main --Insert statements section...Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
ALTER PROCEDURE [dbo].[proc_Update_OP_Single_Week] 
	-- Add the parameters for the stored procedure here
	(@RetailWeek varchar(6),
	@MinDate datetime,
	@MaxDate datetime)
AS
SET @MinDate = (SELECT MIN(Date) FROM tRetailWeeks WHERE AgrWeek = @RetailWeek)
SET @MaxDate = (SELECT MAX(Date) FROM tRetailWeeks WHERE AgrWeek = @RetailWeek)
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
    -- Insert statements for procedure here
SELECT  Right(sales_person,5) AS SalesPer5Char,branch_code,reg_no,tran_no,tran_date,SUM(sales_qty) AS Quantity,SUM(sales_value) AS Net_Amount, SUM(tax_value) AS Tax_Amount
FROM 
SQLIIS.rstar.dbo.saleanalysis
WHERE sales_value<>0 AND tran_date>@MinDate AND tran_Date<@MaxDate
GROUP BY Right(Sales_person,5), branch_code, reg_no, tran_no, tran_date
ORDER BY tran_date
END
[+][-]05.28.2008 at 09:27AM PDT, ID: 21661892

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: SQL Server 2005
Tags: Microsoft, SQL Server, 2005
Sign Up Now!
Solution Provided By: Qlemo
Participating Experts: 2
Solution Grade: A
 
 
[+][-]05.28.2008 at 09:28AM PDT, ID: 21661904

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]05.29.2008 at 01:17AM PDT, ID: 21667218

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628