我正在运行一个必须更新某个表的SQL过程。当我运行该程序时,它表示已成功完成,但是当我尝试调试它时,记录没有更新,它只运行行SET ANSI ON
,然后它给出了成功的消息。我正在使用SQL Server 2012
我错过了什么,有什么需要补充的吗?请在此处查看我的代码:
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 = 'amangelsdorf@avis.co.za'
-- 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
`
答案 0 :(得分:1)
你检查你的计数值 设置@lCount =(从tbl_X203_SMS中选择count(*),其中SMSSent = 0) 如果@lCount> 0
因为你可能得到的值为0所以它不会进入if条件,你可以在if之前使用print(@lCount)并从sql server执行存储过程。
答案 1 :(得分:0)
您显示的代码是创建/更改存储过程的代码,不会执行它,因此成功编译响应。
要执行此过程,您需要使用exec
语句:
exec [dbo].[sp_sms_X203]