?
Solved

SQL Stored Procedure with Parameter

Posted on 2011-09-23
2
Medium Priority
?
450 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
2 Comments
 
LVL 22

Accepted Solution

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

,@EndDate DATETIME
0
 

Author Closing Comment

by:dk04
ID: 36590984
Unbelievable, thanks.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month15 days, 1 hour left to enroll

839 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