Solved

SQL Stored Procedure with Parameter

Posted on 2011-09-23
2
443 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
ID: 36590964
Missing comma between parameters

,@EndDate DATETIME
0
 

Author Closing Comment

by:dk04
ID: 36590984
Unbelievable, thanks.
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (http://dev.mysql.com/doc/refm…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

831 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