我正在运行必须更新某个表的SQL过程。当我运行这个程序时,它说成功完成了,但是当我尝试调试它时记录没有更新,它只运行SET ANSI ON
,然后它给出了成功的消息。我正在使用SQL服务器2012SQL过程执行第一行然后停止
我错过了什么,有什么我需要添加?看到这里我的代码:
USE [CADDe_ProdCopy]
GO
/****** Object: StoredProcedure [dbo].[sp_sms_X203] Script Date: 2015/09/03 08:28:15 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[sp_sms_X203]
as
declare @lCount int
set @lCount = (select count(*) from tbl_X203_SMS where SMSSent = 0)
if @lCount > 0
begin
DECLARE @cSMSeMail varchar(100)
declare @cSMSType varchar(10)
declare @cSMSSent int
declare @cRA varchar(10)
declare @cWizard varchar(7)
declare @cCName varchar(26)
declare @cContact varchar(30)
declare @cUsed_KM int
declare @cAmount_Due decimal(18, 2)
declare @cSMSMessage varchar(160)
declare @cvblf varchar(1)
declare @cCheckInDt datetime
declare @cCheckOutDt datetime
declare @err int
set @cvblf = '|'
declare lcursor CURSOR FOR
Select SMSType, RA, CName, Contact, Used_KM, Amount_Due, eMail, [CheckInDateTime] ,[CheckOutDateTime]
From tbl_X203_SMS WHERE SMSSent = 0
open lcursor
fetch next from lcursor into @cSMSType, @cRA, @cCName, @cContact, @cUsed_KM, @cAmount_Due, @cSMSeMail, @cCheckInDt, @cCheckOutDt
while @@FETCH_STATUS = 0
begin
--SET @cContact = '+27834115771'
--SET @cSMSeMail = '[email protected]'
-- Check that the date of the checkin is within same day
if rtrim(ltrim(@cSMSType)) = 'CheckIn'
begin
if datediff(day,@cCheckInDt,getdate()) = 0
begin
SET @cSMSMessage = left('Thank you '+ @cCName +' for renting with AVIS.',160)
SET @cSMSMessage = left(@cSMSMessage + ' RA#' + @cRA + 'Retrieve your invoice at http://www.avis.co.za/inv' ,160)
--if @cAmount_Due > 0
-- SET @cSMSMessage = left(@cSMSMessage + @cvbLf + 'AMT:R ' + cast(@cAmount_Due as varchar),160)
exec sp_sms_xml_post @cContact, @cSMSMessage, @cSMSeMail
end
end
-- Check that the date of the checkout is within same day
if rtrim(ltrim(@cSMSType)) = 'CheckOut'
begin
if datediff(day,@cCheckOutDt,getdate()) = 0
begin
--SET @cSMSMessage = left('Thank you for choosing AVIS.' + @cvbLf + 'For any assistance contact the AVIS Careline on Tel: 0800001669' ,160)
SET @cSMSMessage = left('Thank you for choosing AVIS. ' + @cvbLf + 'Kindly contact 0800001669 for any roadside or emergency assistance.' ,160)
exec sp_sms_xml_post @cContact, @cSMSMessage, @cSMSeMail
end
end
set @err = @@error
if @err = 0
begin
--print 'no error'
update tbl_X203_SMS set SMSSent = 1 where SMSType = @cSMSType and RA = @cRA
end
fetch next from lcursor into @cSMSType, @cRA, @cCName, @cContact, @cUsed_KM, @cAmount_Due, @cSMSeMail, @cCheckInDt, @cCheckOutDt
end
close lcursor
deallocate lcursor
end
`
所以这是创建/修改存储过程的代码并不会执行。为此,您需要使用exec [dbo]。[sp_sms_X203] –
@SteveFord非常感谢,我认为我有点不小心,现在我已经使用您的建议创建了一份工作,并且它的作用像一个魅力,顺便说一句,怎么做然后,我将您的意见标记为答案:) – Ronny
我会将其添加为答案,您可以将其标记为答案 –