Solved

SQL Stored Procedure with Parameter

Posted on 2011-09-23
2
441 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 500 total points
Comment Utility
Missing comma between parameters

,@EndDate DATETIME
0
 

Author Closing Comment

by:dk04
Comment Utility
Unbelievable, thanks.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

728 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now