0

recentemente resolvi mudar de uso de banco de dados do MySQL server para o mssql(sql server versão 2012) até ai tudo bem o que acontece é que algumas coisas não conseguir refazer-las

se alguém poder me ajudar a terminar a procedure pois onde se encontra " comentado " aparece erro de sintaxe

vou posta o código que eu tentando recriar(CODIGO ORIGINAL)

Here is the google translate results:

I recently decided to change database usage from MySQL server to mssql (sql server version 2012) so far so well what happens is some things can't redo them

if anyone can help me finish the procedure because where is "commented" appears syntax error

I will post the code that I am trying to recreate (ORIGINAL CODE)

    CREATE DEFINER=`root`@`localhost` PROCEDURE `ProcGetMessageMemberInfo_One`(IN @PlayerUID int, IN friend_uid int)
BEGIN
    DECLARE u_id,
            unknown_1,
            unknown_2,
            unknown_3,
            unknown_4,
            unknown_5,
            unknown_6,
            flag_1,
            flag_state,
            player_flag INT(10) DEFAULT 0;
    DECLARE nickname VARCHAR(23);
    DECLARE apelido_in VARCHAR(12);
    DECLARE FINISHED INT DEFAULT 0;

    DECLARE MSN_CURSOR CURSOR FOR
    (   SELECT  a.nick,
                b.uid_friend,
                b.apelido,
                b.unknown1,
                b.unknown2,
                b.unknown3,
                b.unknown4,
                b.unknown5,
                b.unknown6,
                b.flag1,
                b.state_flag,
                @Flag := 1 AS FLAG_PLAYER
        FROM account a, pangya_friend_list b
        WHERE b.uid = @PlayerUID AND a.uid = b.uid_friend AND b.uid_friend = friend_uid
    )
    UNION ALL
    (   SELECT  a.nick,
                @uid_fr := c.member_uid as uid_friend,
                @apel := "" as apelido,
                @unk1 := -1 as unknwon1,
                @unk2 := 0 as unknwon2,
                @unk3 := -1 as unknwon3,
                @unk4 := 0 as unknwon4,
                @unk5 := 0 as unknwon5,
                @unk6 := 0 as unknown6,
                @flag1 := -1 as flag1,
                @flag4 := 0 as state_flag,
                @Flag := 2 AS FLAG_PLAYER
        FROM account a, pangya_guild_member c
        WHERE c.GUILD_UID = (SELECT i.GUILDINDEX FROM Pangya_Member i, pangya_guild_member j WHERE i.UID = @PlayerUID AND i.GUILD_ID = j.GUILD_ID AND j.GUILD_MEMBER_UID = @PlayerUID AND j.GUILD_MEMBER_STATUS < 9)
        AND c.member_uid = a.uid AND c.member_uid = friend_uid AND c.MEMBER_STATE_FLAG != 9
    );

    DECLARE CONTINUE HANDLER
        FOR NOT FOUND SET FINISHED = 1;

    DROP TEMPORARY TABLE IF EXISTS `temp_msn_one`;
    CREATE TEMPORARY TABLE `temp_msn_one`(nick VARCHAR(23) NOT NULL,
                                      uid INT(10) NOT NULL,
                                      apelido VARCHAR(12),
                                      unknown1 INT(10),
                                      unknown2 INT(10),
                                      unknown3 INT(10),
                                      unknown4 INT(10),
                                      unknown5 INT(10),
                                      unknown6 INT(10),
                                      flag1 INT(10),
                                      state_flag INT(10),
                                      FLAG_PLAYER INT(10));
    OPEN MSN_CURSOR;

    MSN_LOOP : LOOP
        FETCH MSN_CURSOR INTO nickname, u_id, apelido_in, unknown_1, unknown_2, unknown_3,
                              unknown_4, unknown_5, unknown_6, flag_1, flag_state, player_flag;

        IF FINISHED = 1 THEN
            LEAVE MSN_LOOP;
        END IF;

        IF (SELECT uid FROM temp_msn_one WHERE UID = u_id) IS NOT NULL THEN
            UPDATE temp_msn_one SET FLAG_PLAYER = FLAG_PLAYER + player_flag WHERE UID = u_id;
        ELSE
            INSERT INTO temp_msn_one VALUES(nickname, u_id, apelido_in, unknown_1, unknown_2, unknown_3,
                                        unknown_4, unknown_5, unknown_6, flag_1, flag_state, player_flag);
        END IF;
    END LOOP MSN_LOOP;

    CLOSE MSN_CURSOR;

    SELECT * FROM temp_msn_one;
END

replica do codigo acima em mssql

replica of the code above in mssql

    USE [DB_Pangya]
GO
/****** Object:  StoredProcedure [dbo].[ProcGetMessageMemberInfo_One]    Script Date: 02/08/2019 13:04:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[ProcGetMessageMemberInfo_One] 

@PLAYER_UID INT,
 @friend_uid int
AS
BEGIN
   SET NOCOUNT ON;
    DECLARE @u_id INT =0;
    DECLARE @unknown_1 INT =0;
    DECLARE @unknown_2 INT =0;
    DECLARE @unknown_3 INT =0;
    DECLARE @unknown_4 INT =0;
    DECLARE @unknown_5 INT =0;
    DECLARE @unknown_6 INT =0;
    DECLARE @flag_1 INT =0;
    DECLARE @flag_state INT =0;
    DECLARE @player_flag INT = 0;
    DECLARE @nickname VARCHAR(23);
    DECLARE @apelido_in VARCHAR(12);
    DECLARE @FINISHED INT = 0;
    DECLARE @uid_fr INT  =0;
    DECLARE @apel VARCHAR(23) = '';
    DECLARE @unk1 INT =  -1;
    DECLARE @unk2 INT =  0;
    DECLARE @unk3 INT =  -1;
    DECLARE @unk4 INT =  0;
    DECLARE @unk5 INT =  0;
    DECLARE @unk6 INT =  0;
    DECLARE @flag1 INT =  -1;
    DECLARE @flag4 INT =  0;
    DECLARE @Flag INT =  2;

    DECLARE MSN_CURSOR CURSOR FOR
    (   SELECT  a.Nickname,
                b.Friend_UID,
                b.Friend_Nick,
                b.UN,
                b.UN2,
                b.UN3,
                b.UN4,
                b.UN5,
                b.UN6,
                b.flag1,
                b.StatusFlag,
                 1 AS FLAG_PLAYER
        FROM Pangya_Member a, pangya_friend_list b
        WHERE b.uid = @PLAYER_UID AND a.uid = b.Friend_UID AND b.Friend_UID = @friend_uid
    )

     UNION ALL
    (   SELECT  a.Nickname,
                c.GUILD_MEMBER_UID as uid_friend,
                @apel as apelido,
                @unk1  as unknwon1,
                @unk2  as unknwon2,
                @unk3  as unknwon3,
                @unk4 as unknwon4,
                @unk5 as unknwon5,
                @unk6  as unknown6,
                @flag1 as flag1,
                @flag4 as state_flag,
                @Flag  AS FLAG_PLAYER
        FROM pangya_member a, pangya_guild_member c
        WHERE c.GUILD_ID  = (SELECT i.GUILDINDEX FROM Pangya_Member i, pangya_guild_member j WHERE i.UID = @PLAYER_UID AND i.GUILDINDEX = j.GUILD_ID AND j.GUILD_MEMBER_UID = @PLAYER_UID AND j.GUILD_MEMBER_STATUS < 9)
         and c.GUILD_MEMBER_UID = a.uid AND c.GUILD_MEMBER_UID = @friend_uid AND c.GUILD_MEMBER_STATUS != 9
    );

    --DECLARE CONTINUE HANDLER FOR NOT FOUND SET @FINISHED = 1;


   IF (OBJECT_ID('TEMPDB..#temp_msn_one') IS NOT NULL)
     DROP TABLE #temp_msn_one
     create table #temp_msn_one(nick VARCHAR(23) NOT NULL,
                                      uid INT NOT NULL,
                                      apelido VARCHAR(12),
                                      unknown1 INT,
                                      unknown2 INT,
                                      unknown3 INT,
                                      unknown4 INT,
                                      unknown5 INT,
                                      unknown6 INT,
                                      flag1 INT,
                                      state_flag INT,
                                      FLAG_PLAYER INT);

--OPEN MSN_CURSOR;

  --  MSN_LOOP : LOOP
        --FETCH MSN_CURSOR INTO @nickname, @u_id, @apelido_in, @unknown_1, @unknown_2, @unknown_3,
        --                    @unknown_4, @unknown_5, @unknown_6, @flag_1, @flag_state, @player_flag;

  --      IF @FINISHED = 1 begin
        --  LEAVE MSN_LOOP;
        --END

  --      IF (SELECT uid FROM #temp_msn_one WHERE UID = @u_id) IS NOT NULL begin
        --  UPDATE #temp_msn_one SET FLAG_PLAYER = FLAG_PLAYER + @player_flag WHERE UID = @u_id;
        --ELSE
        --  INSERT INTO #temp_msn_one VALUES(@nickname, @u_id, @apelido_in, @unknown_1, @unknown_2, @unknown_3,
        --                    @unknown_4, @unknown_5, @unknown_6, @flag_1, @flag_state, @player_flag);
        --END
  --  END LOOP MSN_LOOP;

    --CLOSE MSN_CURSOR;

    SELECT * FROM #temp_msn_one;

END

1 Resposta 1

0

Olá substitui a parte que comentaste por este código...não criei a tabela para validar, mas será algo por aí. Valida e dá feedback.

    DECLARE MSN_CURSOR CURSOR FOR SELECT * FROM #temp_msn_one;

    OPEN MSN_CURSOR  
    FETCH NEXT FROM MSN_CURSOR INTO @nickname, @u_id, @apelido_in, @unknown_1, @unknown_2, @unknown_3,
                                @unknown_4, @unknown_5, @unknown_6, @flag_1, @flag_state, @player_flag

    WHILE @@FETCH_STATUS = 0  
    BEGIN  
        IF EXISTS (SELECT uid FROM #temp_msn_one WHERE UID = @u_id)
          UPDATE #temp_msn_one SET FLAG_PLAYER = FLAG_PLAYER + @player_flag WHERE UID = @u_id;
        ELSE
            INSERT INTO #temp_msn_one VALUES(@nickname, @u_id, @apelido_in, @unknown_1, @unknown_2, @unknown_3,
                           @unknown_4, @unknown_5, @unknown_6, @flag_1, @flag_state, @player_flag);
        END

        FETCH NEXT FROM MSN_CURSOR INTO @nickname, @u_id, @apelido_in, @unknown_1, @unknown_2, @unknown_3,
                                @unknown_4, @unknown_5, @unknown_6, @flag_1, @flag_state, @player_flag 
    END 

    CLOSE MSN_CURSOR  
    DEALLOCATE MSN_CURSOR 
10
  • eu vi que faltou o " SELECT * FROM #temp_msn_one; " e o "END" para encerrar o codigo, será se o procedimento será criado?
    – LuisMK
    Commented 2/08/2019 às 19:42
  • esta parte também foi comentada, sei que existe diferença entre as duas linguagens
    – LuisMK
    Commented 2/08/2019 às 19:44
  • sou meio leigo e não sei como faço isso funcionar > DECLARE CONTINUE HANDLER FOR NOT FOUND SET @FINISHED = 1; <
    – LuisMK
    Commented 2/08/2019 às 19:44
  • Precisas do select final para alguma coisa? Eu tipicamente quando quero utilizar uma SP para criar ou editar, crio uma variável INT = 0, depois fazes SET 1 se fizer update e SET 2 se fizer insert, e retornas esse valor da variável. Commented 2/08/2019 às 19:46
  • Obrigado ! tecnicamente funcionou, mas houve um erro ao tentar consultar a proc
    – LuisMK
    Commented 2/08/2019 às 19:48

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .