?
Solved

SQL Stored Procedure with Parameter

Posted on 2011-09-23
2
Medium Priority
?
447 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 2000 total points
ID: 36590964
Missing comma between parameters

,@EndDate DATETIME
0
 

Author Closing Comment

by:dk04
ID: 36590984
Unbelievable, thanks.
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
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

762 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