IF EXISTS (SELECT * FROM [dbo].[sysobjects] WHERE id = object_id(N'[dbo].[BEGINNER_ITEM]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[BEGINNER_ITEM]
GO
IF EXISTS (SELECT * FROM [dbo].[sysobjects] WHERE id = object_id(N'[dbo].[GIVE_BEGINNER_ITEM]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE [dbo].[GIVE_BEGINNER_ITEM]
GO
CREATE TABLE [dbo].[BEGINNER_ITEM] (
[iClass] [smallint] NOT NULL ,
[strClass] [char] (10) NULL ,
[Gold] [bigint] NULL DEFAULT (0),
[strItem] [binary](800) NULL
) ON [PRIMARY]
GO
INSERT INTO [dbo].[BEGINNER_ITEM] (iClass, strClass, Gold, strItem) VALUES ( 1, 'Warrior', 0, Cast(0 as BINARY(800)));
INSERT INTO [dbo].[BEGINNER_ITEM] (iClass, strClass, Gold, strItem) VALUES ( 2, 'Rogue', 0, Cast(0 as BINARY(800)));
INSERT INTO [dbo].[BEGINNER_ITEM] (iClass, strClass, Gold, strItem) VALUES ( 3, 'Magician', 0, Cast(0 as BINARY(800)));
INSERT INTO [dbo].[BEGINNER_ITEM] (iClass, strClass, Gold, strItem) VALUES ( 4, 'Priest', 0, Cast(0 as BINARY(800)));
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[GIVE_BEGINNER_ITEM]
@strUserId varchar(21)
AS
BEGIN
DECLARE @Class smallint
SELECT @Class = CAST(SUBSTRING(CAST(Class AS varchar(3)), 2, 2) AS int) FROM USERDATA WHERE strUserId = @strUserId
IF @Class = 1 OR @Class = 5 OR @Class = 6
SET @Class = 1
IF @Class = 2 OR @Class = 7 OR @Class = 8
SET @Class = 2
IF @Class = 3 OR @Class = 9 OR @Class = 10
SET @Class = 3
IF @Class =4 OR @Class = 11 OR @Class = 12
SET @Class = 4
UPDATE USERDATA SET strItem = (SELECT strItem FROM BEGINNER_ITEM WHERE iClass = @Class), Gold = (SELECT Gold FROM BEGINNER_ITEM WHERE iClass = @Class) WHERE strUserId = @strUserId
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO