ALTER procedure [dbo].[Eng_MyAddOrEdtPro]
@My_Cocode int,
@Type int,
@My_KeyId uniqueidentifier,
@My_PCode int,
@My_SCode int,
@My_PName nvarchar(36),
@My_SName nvarchar(36),
@My_Order int,
@My_Apply_UserName nvarchar(36),
@My_Apply_UserId uniqueidentifier,
@My_Error int output,
@My_ErrorMessage nvarchar(50) output
as
declare @error int;
declare @errormessage nvarchar(50);
set @error=0;
set @errormessage='返回成功';
BEGIN
DECLARE @My_SKeyId nvarchar(36);
DECLARE @My_SCode2 int;
DECLARE @My_PKeyId nvarchar(36);
DECLARE @My_PCode2 int;
SELECT @My_SCode2=My_SCode,@My_SKeyId=My_SKeyId FROM Mys A WHERE A.My_Cocode=@My_Cocode AND (My_SCode=@My_SCode OR A.My_SName=@My_SName) AND My_Status=1;
SELECT @My_PCode2=My_PCode,@My_PKeyId=My_PKeyId FROM Mys A WHERE A.My_Cocode=@My_Cocode AND (My_PCode=@My_PCode OR A.My_PName=@My_PName) AND My_Status=1;
IF ISNULL(@My_SCode,'')='' OR ISNULL(@My_SCode,'')!=@My_SCode2 OR ISNULL(@My_SKeyId,'')='' OR ISNULL(@My_PCode,'')='' OR ISNULL(@My_PCode,'')!=@My_PCode2 OR ISNULL(@My_PKeyId,'')=''
BEGIN
SET @error=1;
SET @errormessage = '不匹配!';
-- RETURN;
END
IF @error=0
BEGIN
IF @Type=1
BEGIN
INSERT INTO Mys VALUES (@My_KeyId,@My_Cocode,@My_PKeyId,@My_SKeyId,@My_PCode2,@My_SCode2,@My_PName,@My_SName,1,@My_Order,@My_Apply_UserName,@My_Apply_UserId,GETDATE(),@My_Apply_UserName,@My_Apply_UserId,GETDATE());
END
IF @Type=2
BEGIN
UPDATE Mys SET My_SName=@My_SName,@My_PName=My_PName,My_Order=@My_Order,My_UpdateUserName=@My_Apply_UserName,My_UpdateUserId=@My_Apply_UserId,My_UpdateDate=GETDATE() WHERE My_KeyId=@My_KeyId AND My_Status=1;
END
SET @errormessage =@My_SName+ '更新成功!';
END文章来源:https://www.toymoban.com/news/detail-595419.html
SET @My_Error=@error;SET @My_ErrorMessage=@errormessage
SET @My_SKeyId=NULL;
SET @My_PKeyId=NULL;
SET @My_SCode2=NULL;
SET @My_PCode2=NULL;
SET @error=NULL;
SET @errormessage=NULL;
END
文章来源地址https://www.toymoban.com/news/detail-595419.html
到了这里,关于sqlserver 如何使用书写存储过程的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!