USE [MuOnline]
GO
/****** Object: StoredProcedure [dbo].[WZ_GuildCreate] Script Date: 05/23/2013 19:32:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[WZ_GuildCreate]
@GuildName varchar(8),
@MasterName varchar(10)
as
BEGIN
DECLARE @ErrorCode int
declare @rightcreations bit
SET @ErrorCode = 0
SET XACT_ABORT ON
Set nocount on
begin transaction
-- Verification right (active)
select @rightcreations = CreateGuild from Character where Name LIKE @MasterName;
IF (@rightcreations <> 1 )
BEGIN
SET @ErrorCode = 1
END
-- création de la guilde
IF ( @ErrorCode = 0 )
BEGIN
INSERT INTO Guild (G_Name, G_Master) VALUES (@GuildName, @MasterName)
IF ( @@Error <> 0 )
BEGIN
SET @ErrorCode = 1
END
END
IF ( @ErrorCode = 0 )
BEGIN
-- insertion du guildmaster dans la table des membres
INSERT GuildMember (Name, G_Name, G_Level) VALUES (@MasterName, @GuildName, 1)
IF ( @@Error <> 0 )
BEGIN
SET @ErrorCode = 2
END
END
-- en cas d'erreur on annule tout
IF ( @ErrorCode <> 0 )
rollback transaction
ELSE
commit transaction
-- on renvoie le code d'erreur
select @ErrorCode
Set nocount off
SET XACT_ABORT OFF
END