I'm having a tough time with this one. I've spent days trying to figure it out.
The stored procedure included below parses out and the procedure is created when I play it. But when I run it, I get this error message:
Server: Msg 170, Level 15, State 1, Line 7
Line 7: Incorrect syntax near 't'.
I can't figure out what this error message means. By my count, line 7 is a blank line. I don't know what 't' it's referring to.
The stored procedure included below parses out and the procedure is created when I play it. But when I run it, I get this error message:
Server: Msg 170, Level 15, State 1, Line 7
Line 7: Incorrect syntax near 't'.
I can't figure out what this error message means. By my count, line 7 is a blank line. I don't know what 't' it's referring to.
Code:
CREATE PROCEDURE usp_AllMailingEntries
@EmpID int = null,
@DateEntered varchar(20) = '%'
AS
Declare @SQL varchar(500),
@WHERE varchar(500)
If @EmpID Is Null
Set @WHERE = ' WHERE bitIsActive = 1 AND DateEntered LIKE ' + @DateEntered
Else
Set @WHERE = ' WHERE bitIsActive = 1 AND DateEntered LIKE ' + @DateEntered + ' AND EmpID = ' + @EmpID
Set @SQL = 'SELECT
FirstName, LastName, Address1, Address2,
City, StateID, StateAbbrev, Province,
Zip, ZipPlus4, Country, Phone,
EmailAddress, HeardAboutID, EmpID,
DateEntered, Comments
FROM People
Left Join States ON People.StateID = States.StateID' + @WHERE
Exec(@SQL)