Solved

SQL Stored Procedure with Parameter

Posted on 2011-09-23
2
446 Views
Last Modified: 2012-05-12
I keep getting the following error when creating this stored procedure.

Msg 102, Level 15, State 1, Procedure spx, Line 3
Incorrect syntax near '@EndDate'.
Msg 137, Level 15, State 2, Procedure spx, Line 24
Must declare the scalar variable "@BeginDate".

CREATE PROCEDURE spx
@BeginDate DATETIME 
@EndDate DATETIME	

AS

SELECT StoreNumber, 
		Date, 
		Sales, 
		DateComp, 
		SalesComp, 
		Labor, 
		CashOS, 
		Comment,
		(Sales-SalesComp)/nullif(SalesComp,0)*100 AS DCompPercent
      
FROM
		(SELECT T1.StoreNumber, T1.Date, T1.Sales, DateAdd(DAY,-371,T1.Date) AS DateComp,
			 (Select Sum (Sales) 
			 FROM Sales 
			 WHERE T1.StoreNumber = Sales.StoreNumber and  Sales.Date = DateAdd(DAY,-371,T1.Date)) 
		AS SalesComp, T1.Labor, T1.CashOS, T1.Comment FROM Sales AS T1) 
S
Where Date BETWEEN @BeginDate and @EndDate
ORDER BY Date DESC, StoreNumber ASC

Open in new window

0
Comment
Question by:dk04
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 22

Accepted Solution

by:
Thomasian earned 500 total points
ID: 36590964
Missing comma between parameters

,@EndDate DATETIME
0
 

Author Closing Comment

by:dk04
ID: 36590984
Unbelievable, thanks.
0

Featured Post

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

691 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