如何解决从IDE运行过程就去了,而如果触发器调用了它就走了
我已经创建了一个触发器,当用户更改文档状态时它将运行。我使用的sql版本是15.0.2000.5,一切正常。取而代之的是,客户拥有12.0.4100.1,并且触发器给了我一些过程上的错误。 该过程的范围是在当前文档中创建新行。当触发器运行该过程时,插入新行,但某些字段未正确编译,并且在客户使用的软件中,这些新行我看不到。
我尝试不使用触发器的过程并完成其工作。我在IDE中尝试触发代码并正确执行其任务。 我尝试调试将一些数据保存在临时表中以查看输入和输出结果,但它们似乎是正确的。 我以为是发出了权限,但我已经用同一用户创建并运行了该权限,但是我尝试了这段代码:
BEGIN TRY
EXEC(N'
USE [master];
GRANT CONTROL SERVER TO [administrator];
');
END TRY
BEGIN CATCH
DECLARE @Donothing INT;
END CATCH;
CREATE TRIGGER <trigger name> ON <document table>
AFTER UPDATE
AS
SET NOCOUNT ON;
-- control status changed
IF UPDATE(Status)
BEGIN
DECLARE @optionCode VARCHAR(6) = 'TRPREV'
DECLARE @documentsType VARCHAR(100)
DECLARE @released VARCHAR(4) = '001'
DECLARE @notReleased VARCHAR(4) = '002'
DECLARE @documentIndex INT
DECLARE @newStatus VARCHAR(4)
-- get all the orders code
SET @documentsType = (SELECT TOP 1 ValueOption FROM Options WHERE OP_Cle = @optionCode)
SELECT @doCpt = DO_Cpt,@newStatus = DO_Status
FROM inserted
INNER JOIN TypeDoc TD ON TD.TD_Code = DO_TypeDoc AND CHARINDEX(TD_Code,@documentsType) > 0
-- delete the previsionelle
IF ( @newStatus = @notReleased )
BEGIN
-- delete some lines
END
ELSE
BEGIN
-- create the previsionelle
IF ( @newStatus = @released OR ISNULL(@newStatus,'') = '' )
BEGIN
EXEC crea_previsionali @doCpt
END
END
END -- update if
GO
这是过程代码:
CREATE PROCEDURE <procedure name>
@DoCpt AS INT
AS
-- declared some variables
DECLARE @Cursor as CURSOR;
-- preare the cursors
SET @Cursor = CURSOR FOR
SELECT Cpt,TypeDoc,ItemType,DateEch,PrixHT,PrixHTMB,ShipToAddresstype,MarginUC_Base
FROM Lignes
WHERE DOCpt=@DoCpt
AND Previsionnelle=0
ORDER BY DOCpt,No
OPEN @Cursor;
FETCH NEXT FROM @Cursor INTO @T_LiCpt,@T_TypeDoc,@T_ItemType,@T_DateEch,@T_PrixHT,@T_PrixHTMB,@T_ShipToAddresstype,@T_MarginUC_Base;
WHILE @@FETCH_STATUS = 0
BEGIN
IF EXISTS (SELECT GR_Pere AS C FROM vw_GrammaireIT WITH(NOLOCK)
WHERE (GR_Type = 0)
AND (GR_Prev = 1)
AND (GR_Fils = @T_TypeDoc)
AND (ItemType = @T_ItemType))
BEGIN
PRINT cast(@T_Cpt as VARCHAR (50))
SELECT @PROV_TD_Code=TD_Code,@PROV_TD_TypePrix=TD_TypePrix,@PROV_TD_ImpStock=ISNULL(TD_ImpStock,0),@PROV_TD_reliquat=ISNULL(TD_Reliquat,@PROV_TD_Transfer=ISNULL(TD_Transfer,0)
FROM vw_GrammaireIT WITH(NOLOCK)
INNER JOIN TypeDoc WITH(NOLOCK) ON Pere=Code
WHERE Fils=@T_TypeDoc and Prev=1 AND ItemType=@T_ItemType
exec sp_CreateProvisional @T_LI_DateEch,@prov,@PROV_TD_Code,@PROV_TD_ImpStock,1,@T_LiCpt,@T_MarginUC_Base,@PROV_TD_reliquat
END
FETCH NEXT FROM @Cursor INTO @T_LiCpt,@T_MarginUC_Base;
CLOSE @Cursor;
DEALLOCATE @Cursor;
GO
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。