title: SQL Procedure execution error while converting datatypes
body: <p>a friend of mine has created a procedure , and he asked me to test it.
  and when i tested it , it didn't work, i don't know why, it always say :  </p>
  
  <pre><code>Msg 50000, Level 16, State 1, Procedure _RoyalCreateInstance, Line
  127 Error occured at RefGameWorld Update/Insert | ERR MSG: Conversion
  failed when converting the varchar value 'GAME_WORLD_NORMALIZE_TYPE_A'
  to data type bit.
  </code></pre>
  
  <p>Procedure : </p>
  
  <pre><code>CREATE PROCEDURE _RoyalCreateInstance 
  @Charname VARCHAR(32), 
  @AreaName VARCHAR(32), 
  @MaxWorlds INT, 
  @MaxPlayers INT, 
  @MinEntranceLevel TINYINT, 
  @MaxEnterPerDay TINYINT, 
  @HorseAllowed BIT, 
  @JobAllowed BIT, 
  @PetAllowed BIT 
  AS 
  
  BEGIN TRAN 
  BEGIN TRY 
  
      DECLARE @JobAllowedString VARCHAR(3) = CASE  
                                              WHEN @JobAllowed = 1  
                                                  THEN 'OFF' 
                                              ELSE 'ON' 
                                             END, 
              @PetAllowedString VARCHAR(3) = CASE 
                                              WHEN @PetAllowed = 1 
                                                  THEN 'OFF' 
                                              ELSE 'ON' 
                                             END, 
              @HorseAllowedString VARCHAR(3) = CASE 
                                                  WHEN @HorseAllowed = 1 
                                                      THEN 'OFF' 
                                                  ELSE 'ON' 
                                               END, 
              @WorldID INT, 
              @RegionID INT, 
              @PosX REAL, 
              @PosY REAL, 
              @PosZ REAL; 
  
      SELECT    @RegionID = LatestRegion, 
              @PosX = PosX, 
              @PosY = PosY, 
              @PosZ = PosZ 
      FROM    SRO_VT_SHARD.._Char  
      WHERE    CharName16 = @Charname 
  
      IF    @RegionID IS NULL 
          BEGIN 
              ROLLBACK TRAN 
              RAISERROR ('Charname not found', 16, 0) 
              RETURN 
          END 
  
      DELETE FROM     SRO_VT_SHARD.._RefGame_World_Config WHERE GroupCodeName128 = 'GROUP_' + @AreaName 
      INSERT INTO     SRO_VT_SHARD.._RefGame_World_Config (Service, GroupCodeName128, ValueCodeName128, Value, Type) 
      VALUES        (1, 'GROUP' + @AreaName, 'GAME_WORLD_NORMALIZE_TYPE', 'GAME_WORLD_NORMALIZE_TYPE_A', 'STRING'), 
                  (1, 'GROUP' + @AreaName, 'ENTER_LIMIT_CONDITION_ENTRY', 'NUM_LIMIT', 'STRING'), 
                  (1, 'GROUP' + @AreaName, 'ENTER_LIMIT_CONDITION_PARTY', 'ON', 'STRING'), 
                  (1, 'GROUP' + @AreaName, 'ENTER_LIMIT_CONDITION_LEVEL_MINIMUM_NUM', CAST(@MinEntranceLevel AS VARCHAR(5)), 'INT32'), 
                  (1, 'GROUP' + @AreaName, 'ENTER_LIMIT_CONDITION_ENTRY_MAXIMUM_NUM', CAST(@MaxEnterPerDay AS VARCHAR(5)), 'INT32'), 
                  (1, 'GROUP' + @AreaName, 'ENTER_LIMIT_CONDITION_REENTRY', 'ON', 'STRING'), 
                  (1, 'GROUP' + @AreaName, 'ENTER_LIMIT_CONDITION_JOB_CLOTHES_TAKE_OFF', @JobAllowedString, 'STRING'), 
                  (1, 'GROUP' + @AreaName, 'ENTER_LIMIT_CONDITION_RIDE_COS_NOT_RIDING', @HorseAllowed, 'STRING'), 
                  (1, 'GROUP' + @AreaName, 'ENTER_LIMIT_CONDITION_TRADE_COS_NOT_RIDING', @PetAllowedString, 'STRING'), 
                  (1, 'GROUP' + @AreaName, 'ENTER_LIMIT_CONDITION_GAME_WORLD_ASSIGNED', 'ON', 'STRING'), 
                  (1, 'GROUP' + @AreaName, 'PARTYMONSTER_SPAWN', 'OFF', 'STRING'), 
                  (1, 'GROUP' + @AreaName, 'ENTER_LIMIT_CONDITION_FRPVP_VOUCHER_TAKE_OFF', 'ON', 'STRING'), 
                  (1, 'GROUP' + @AreaName, 'REF_GAME_WORLD_NPC', 'INS_' + @AreaName, 'STRING') 
  
      IF EXISTS(SELECT * FROM SRO_VT_SHARD.._RefGame_World WHERE WorldCodeName128 = 'INS_' + @AreaName) 
          BEGIN 
              UPDATE    SRO_VT_SHARD.._RefGame_World  
              SET        Type = 1,  
                      WorldMaxCount = @MaxWorlds,  
                      WorldMaxUserCount = @MaxPlayers,  
                      WorldDurationTime = 7200000,  
                      WorldEmptyRemainTime = 300000  
              WHERE    WorldCodeName128 = 'INS_' + @AreaName 
          END 
      ELSE IF NOT EXISTS(SELECT * FROM SRO_VT_SHARD.._RefGame_World WHERE WorldCodeName128 = 'INS_' + @AreaName) 
          BEGIN 
              INSERT INTO SRO_VT_SHARD.._RefGame_World (WorldCodeName128, Type, WorldMaxCount, WorldMaxUserCount, WorldEntryType, WorldEntranceType, WorldLeaveType, WorldDurationTime, WorldEmptyRemainTime, ConfigGroupCodeName128) 
              SELECT        'INS_' + @AreaName, 1, @MaxWorlds, @MaxPlayers, 0, 0, 0, 7200000, 300000, 'GROUP_' + @AreaName     
          END 
  
      IF EXISTS(SELECT * FROM SRO_VT_SHARD.._RefTeleport WHERE CodeName128 LIKE 'GATE_' + @AreaName) 
          BEGIN 
              UPDATE    SRO_VT_SHARD.._RefTeleport 
              SET        GenWorldID = @WorldID 
              WHERE    CodeName128 LIKE 'GATE_' + @AreaName 
  
              SELECT    Service, ID, CodeName128, AssocRefObjCodeName128, AssocRefObjID, ZoneName128, GenRegionID, GenPos_X, GenPos_Y, GenPos_Z, GenAreaRadius, CanBeResurrectPos, CanGotoResurrectPos, GenWorldID 
              FROM    SRO_VT_SHARD.._RefTeleport 
              WHERE    CodeName128 LIKE 'GATE_' + @AreaName 
          END 
      ELSE 
          BEGIN 
              SELECT 'Could''t find _RefTeleport line, after you''ve create a teleporter run the following query: ' 
              SELECT 'UPDATE _RefTeleport SET GenWorldID = @WorldID WHERE CodeName128 LIKE ''PORTERNAMEHERE'' ' 
          END 
  
      SELECT        *, '', 'OLD LINES!!! @_RefInstance_World_Region' 
      FROM        SRO_VT_SHARD.._RefInstance_World_Region 
      WHERE        RegionID = @RegionID 
  
      DELETE FROM    SRO_VT_SHARD.._RefInstance_World_Region WHERE RegionID = @RegionID 
      INSERT INTO SRO_VT_SHARD.._RefInstance_World_Region (WorldID, RegionID) 
      VALUES        (1, @RegionID), 
                  (@WorldID, @RegionID) 
  
      SELECT        'Old lines at _RefInstance_World_Region have been deleted' 
  
      SELECT        *, '', 'OLD LINES!!! @_RefInstance_World_Start_Pos &amp; new ones added' 
      FROM        SRO_VT_SHARD.._RefInstance_World_Start_Pos 
      WHERE        RegionID = @RegionID 
  
      DELETE FROM    SRO_VT_SHARD.._RefInstance_World_Start_Pos 
      INSERT INTO SRO_VT_SHARD.._RefInstance_World_Start_Pos (WorldID, RegionID, PosX, PosY, PosZ, Param) 
      SELECT        @WorldID, @RegionID, @PosX, @PosY, @PosZ, 0 
  
      SELECT        'Old lines at _RefInstance_World_Start_Pos have been deleted &amp; new ones added' 
  
  
  END TRY 
  
  BEGIN CATCH 
      DECLARE        @ErMessage NVARCHAR(2048) = 'Error occured at RefGameWorld Update/Insert | ERR MSG: ' + ERROR_MESSAGE(), 
                  @ErSeverity INT = ERROR_SEVERITY(), 
                  @ErState INT = ERROR_STATE(); 
      RAISERROR    (@ErMessage, @ErSeverity, @ErState) 
      ROLLBACK TRAN 
      RETURN 
  
  END CATCH 
  
  COMMIT TRAN  
  </code></pre>
  
  <p>I hope someone can help me, that'd be much appreciated.</p>