将TSQL查询转换为MySQL

时间:2017-08-18 00:32:20

标签: mysql tsql phpmyadmin

我需要将此tSQL查询转换为MySQL查询版本5.7.14 我尝试使用以下语法声明参数

declare @commissionType INT;

但我走到了死胡同,需要帮助来转换此查询

CREATE PROCEDURE MyProc
@chainId int
as 
BEGIN
    declare @commissionMethod int
    declare @commissionType int
    declare @value decimal(18,2)

    set @commissionMethod = 1
    set @value = 200000
    set @commissionType = (select  CommissionType from CommissionRules 
    where ChainId = @chainId )

        IF(@commissionMethod = 1)
        BEGIN
            print('alert')
            select (Fixed * @value) / 100 from CommissionRules where ChainId = @chainId  
        END
END

2 个答案:

答案 0 :(得分:1)

这样的事情:

DELIMITER $$

CREATE PROCEDURE MyProc (
    in_chainId unsigned
) as 
BEGIN
    select v_CommissionType := CommissionType,
           v_commissionMethod = 1,
           v_value = 200000
    from CommissionRules 
    where ChainId = in_chainId;

    if v_commissionMethod = 1 then
        select 'alert';

        select (Fixed * v_value) / 100
        from CommissionRules
        where ChainId = in_chainId  
    end if;
END;$$

DELIMITER ;

答案 1 :(得分:1)

这几乎是一个字面转换。但检查你的逻辑。它没有任何意义。 v_commissionMethod始终为1,并且在选择值后甚至未使用v_commissionType

 DELIMITER //

    CREATE PROCEDURE MyProc (
    p_chainId int)
    BEGIN
        declare v_commissionMethod int;
        declare v_commissionType int;
        declare v_value decimal(18,2);

        set v_commissionMethod = 1;
        set v_value = 200000;
        select  CommissionType into v_commissionType from CommissionRules 
        where ChainId = p_chainId ;

            IF(v_commissionMethod = 1)
            THEN
                /* print('alert') */
                select (Fixed * v_value) / 100 from CommissionRules where ChainId = p_chainId;  
            END IF;
    END;
    //

    DELIMITER ;