'IN'关键字附近的语法错误不正确

时间:2015-08-17 07:16:43

标签: mysql sql-server

如何在sql server中使用这个mysql查询?

如果我在sql server中使用相同的语法,那么我收到以下错误。

  

'IN'关键字

附近的语法错误不正确
int comparison( const void *p1, const void *p2 )
{
    const card *c1 = ( const card * )p1;
    const card *c2 = ( const card * )p2;

    int color_cmp = strcmp( c1->color, c2->color ); 

    if ( color_cmp < 0 )
    {
        return -1;
    }
    else if ( color_cmp > 1 )
    {
        return 1;
    }
    else
    { 
        return ( c2->rank < c1->rank ) - ( c1->rank < c2->rank );
    }
}

1 个答案:

答案 0 :(得分:0)

简单地用标准的sql if语句替换mysql case语句可以解决您的问题。

    select
        count(1) as total_record
    from
        sms_allocation left join sms_api_definition on sms_allocation.sms_api_definition_id = sms_api_definition.sms_api_definition_id
    where
        case when 
            '1' = 1 or '4,26,28,31,32,33,37,41,53,56,58,62,63,66,71,72,73,75,76,77,81' = 81 or '4,26,28,31,32,33,37,41,53,56,58,62,63,66,71,72,73,75,76,77,81' = 82
        then
            case when 
                '0' != '0'
            then
                reseller_id in (
                    select
                        reseller_id
                    from
                        sms_allocation
                    where
                        reseller_id in (0)
                 )
             else
                 reseller_id in (
                     select
                         reseller_id
                     from
                         sms_allocation
                 )
             end
       else    
           reseller_id in (
               select
                   reseller_id
               from
                   sms_allocation
               where
                   reseller_id in (0)
       end
       and 
          sms_allocate_to = 'Company'
);

更新:将||替换为or,抱歉,我错过了。