[英]incorrect syntax error near 'IN' keyword
如何在SQL Server中使用此mysql查詢?
如果我在sql server中使用了相同的語法,則出現以下錯誤。
'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');
只需將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'
);
更新:替換||
與or
,對不起,我錯過了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.