2015-08-17 2 views
0

Как я могу использовать этот запрос mysql в sql-сервере?неправильная синтаксическая ошибка рядом с ключевым словом 'IN'

Если я использовал тот же синтаксис в sql-сервере, то получаю следующую ошибку.

некорректной ошибка синтаксиса около ключевого слова 'IN'

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 if(('1' = 1 || '4,26,28,31,32,33,37,41,53,56,58,62,63,66,71,72,73,75,76,77,81' = 81 || '4,26,28,31,32,33,37,41,53,56,58,62,63,66,71,72,73,75,76,77,81' = 82), 
     if('0'!='0',reseller_id in (
     select reseller_id 
     from sms_allocation 
     where reseller_id in (0)),reseller_id in (
      select reseller_id 
      from sms_allocation) 
     ), reseller_id in (
      select reseller_id 
      from sms_allocation 
      where reseller_id in (0)) and sms_allocate_to='Company'); 
+0

Я переношу код mysql в MS sql – HUM

ответ

0

Просто заменить оператор MySQL if со стандартным SQL 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' 
); 

Update: заменить || с or, жаль, что я пропустил это.

+0

У меня появились ошибки: Неправильный синтаксис рядом с ключевым словом 'in'. Неверный синтаксис рядом с ключевым словом 'else'. Неверный синтаксис рядом с ключевым словом «конец». – HUM

+0

Обновленный ответ, пожалуйста, попробуйте. –

+0

да после этого только я получил ошибку – HUM