|
kirkeby
Yak Posting Veteran
57 Posts |
Posted - 2001-06-20 : 14:52:54
|
| I'm having a problem with this sproc and wonder if someone could kindly tell me where I've screwed up. Here's my error messages when checking syntax:Error 156: Incorrect syntax near the keyword 'EXEC'. Incorrect syntax near the keyword 'EXEC'. Incorrect syntax near the keyword 'EXEC'. Incorrect syntax near the keyword 'EXEC'.OK. So it doesn't like my IF routine structure at the bottom of the sproc. If I put the DECLARE statements at the top and remove the SET statements from the IF routines, then that error goes away. However, putting the SET statements anywhere else in the sproc generates errors. Help! (and thank you!)CREATE PROCEDURE NotifyScripterASset nocount onDECLARE @RequestID intDECLARE @ScripterID intDECLARE @ScripterEmail intDECLARE @ScripterNotified bitDECLARE @RequesterName varchar(60)DECLARE @RequestType char(1)DECLARE @RequestDate datetimeDECLARE @Description varchar(140)DECLARE NotifyCursor CURSOR FOR SELECT R.Request_ID, R.Scripter_ID, RSD.Scripter_Email, R.Scripter_Notified, R.Requester_Name, R.Request_Type, R.Request_Date, (CASE WHEN ReqCommon.Request_Type = 'S' THEN ReqScripting.Product_Name + ' ' + ReqScripting.Product_Version WHEN ReqCommon.Request_Type = 'T' THEN ReqTesting.Product_Name + ' ' + ReqTesting.Product_Version WHEN ReqCommon.Request_Type = 'W' THEN ReqWTS.Product_Name + ' ' + ReqWTS.Product_Version WHEN ReqCommon.Request_Type = 'O' THEN ReqOther.ProjectDescription END) AS Description FROM ReqCommon R LEFT OUTER JOIN ReqScripterDef RSD ON R.Scripter_ID = RSD.Scripter_ID LEFT OUTER JOIN ReqScripting ON R.Request_ID = ReqScripting.Request_ID LEFT OUTER JOIN ReqTesting ON R.Request_ID = ReqTesting.Request_ID LEFT OUTER JOIN ReqWTS ON R.Request_ID = ReqWTS.Request_ID LEFT OUTER JOIN ReqOther ON R.Request_ID = ReqOther.Request_ID WHERE (R.Scripter_ID <> 9) AND (R.Scripter_Notified = 0) OPEN NotifyCursor FETCH NEXT FROM NotifyCursor INTO @RequestID, @ScripterID, @ScripterEmail, @ScripterNotified, @RequesterName, @RequestType, @RequestDate, @DescriptionWHILE (@@FETCH_STATUS = 0)BEGINIF @RequestType = 'S'BEGINDECLARE @msgS varchar(1000)SET @msgS = 'Request ID:' + CHAR(9) + CHAR(9) + CAST(@RequestID as varchar(10)) + CHAR(10) + 'Requester Name:' + CHAR(9) + @RequesterName + CHAR(10) + 'Request Date:' + CHAR(9) + CONVERT(varchar(10), @RequestDate, 101) + CHAR(10 + 'Description:' + (CHAR(9) + @Description + CHAR(13) + CHAR(13) + 'You have been assigned a new request. If you would like to view the details of this request, please click on this link (http://dboas.bpweb.bp.com/StatusDetailScripting.asp?Request_ID=' + CAST(@RequestID as varchar(10)) + ').'EXEC master..xp_sendmail @recipients=@ScripterEmail, @subject='You have been assigned a new request', @dbuse='Staging', @message=@msgSENDELSE IF @RequestType = 'T'BEGINDECLARE @msgT varchar(1000)SET @msgT = 'Request ID:' + CHAR(9) + CHAR(9) + CAST(@RequestID as varchar(10)) + CHAR(10) + 'Requester Name:' + CHAR(9) + @RequesterName + CHAR(10) + 'Request Date:' + CHAR(9) + CONVERT(varchar(10), @RequestDate, 101) + CHAR(10 + 'Description:' + (CHAR(9) + @Description + CHAR(13) + CHAR(13) + 'You have been assigned a new request. If you would like to view the details of this request, please click on this link (http://dboas.bpweb.bp.com/StatusDetailTesting.asp?Request_ID=' + CAST(@RequestID as varchar(10)) + ').'EXEC master..xp_sendmail @recipients=@ScripterEmail, @subject='You have been assigned a new request', @dbuse='Staging', @message=@msgTENDELSE IF @RequestType = 'O'BEGINDECLARE @msgO varchar(1000)SET @msgO = 'Request ID:' + CHAR(9) + CHAR(9) + CAST(@RequestID as varchar(10)) + CHAR(10) + 'Requester Name:' + CHAR(9) + @RequesterName + CHAR(10) + 'Request Date:' + CHAR(9) + CONVERT(varchar(10), @RequestDate, 101) + CHAR(10 + 'Description:' + (CHAR(9) + @Description + CHAR(13) + CHAR(13) + 'You have been assigned a new request. If you would like to view the details of this request, please click on this link (http://dboas.bpweb.bp.com/StatusDetailOther.asp?Request_ID=' + CAST(@RequestID as varchar(10)) + ').'EXEC master..xp_sendmail @recipients=@ScripterEmail, @subject='You have been assigned a new request', @dbuse='Staging', @message=@msgOENDELSE IF @RequestType = 'W'BEGINDECLARE @msgW varchar(1000)SET @msgW = 'Request ID:' + CHAR(9) + CHAR(9) + CAST(@RequestID as varchar(10)) + CHAR(10) + 'Requester Name:' + CHAR(9) + @RequesterName + CHAR(10) + 'Request Date:' + CHAR(9) + CONVERT(varchar(10), @RequestDate, 101) + CHAR(10 + 'Description:' + (CHAR(9) + @Description + CHAR(13) + CHAR(13) + 'You have been assigned a new request. If you would like to view the details of this request, please click on this link (http://dboas.bpweb.bp.com/StatusDetailWTS.asp?Request_ID=' + CAST(@RequestID as varchar(10)) + ').'EXEC master..xp_sendmail @recipients=@ScripterEmail, @subject='You have been assigned a new request', @dbuse='Staging', @message=@msgWENDENDCLOSE NotifyCursorDEALLOCATE NotifyCursor |
|