关键字附近的语法不正确'其中'将MySQL转换为MSSQL时

时间:2014-08-13 15:40:11

标签: php mysql sql sql-server

所以我试图将一些东西从MySql转换为MSSQL 2012,问题是我不知道Sql很清楚这个语句有什么问题。当我使用与MSSQL DB相同的信息对MySql DB运行时,我得到一个响应。

我收到错误:

关键字'where'附近的语法不正确。消息:156,等级:15,状态:1,程序:,行:11

select distinct
    coalesce(s.state_prov, ls.state_prov, 'State Unknown') as state_prov 
from 
    circuit_id_locations cid
join
    location_states ls
left join
    location_states s 
on 
cid.state_prov = s.abreviation
where 
ls.idx = '99'
or 
cid.id = '99'

2 个答案:

答案 0 :(得分:1)

你有一个没有'on statement'的连接语句

>>>MISSING JOIN TYPE (inner/left/right/cross)<<< join
    location_states ls
>>>MISSING ON<<<

左连接     location_states s

答案 1 :(得分:1)

您的JOIN条款比ON条款多CROSS JOIN,将您的正常加入转为select distinct coalesce(s.state_prov, ls.state_prov, 'State Unknown') as state_prov from circuit_id_locations cid CROSS join location_states ls left join location_states s on cid.state_prov = s.abreviation where ls.idx = '99' or cid.id = '99' 以使其有效。

{{1}}