我正在運行必須更新某個表的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
我會將其添加爲答案,您可以將其標記爲答案 –