嘿伙计们,我用我非常棒的MS SQL技术编写了这个MS SQL脚本,我怎样才能让它在MySQL中运行?它失败了一些字符串函数:(不太了解MySQL!
SELECT i.id as ID, e.code as EMPCODE, lower(e.email_address) as EMAIL
from load_incidents i , dim_employee e
WHERE
( (i.involvedemail = e.email_address)
or (replace(lower(e.preferred_name+e.last_name),' ', '') = replace(lower(i.involvedname),' ', ''))
or (replace(lower(e.preferred_name+e.last_name),' ', '') like replace(lower(i.involvedname),' ', '')+'%')
or (replace(lower(e.first_name+e.last_name),' ', '') = replace(lower(i.involvedname),' ', ''))
or (replace(lower(e.first_name+e.last_name),' ', '') like replace(lower(i.involvedname),' ', '')+'%')
or (replace(lower(e.employee_name),' ','') = replace(lower(i.involvedname),' ',''))
)
and charindex(' ',e.first_name) = 0
and (i.involvedemail= 'none available' or i.involvedemail is null or i.involvedemail = '')
UNION
SELECT i.id as ID, e.code as EMPCODE, lower(e.email_address) as EMAIL
from load_incidents i , dim_employee e
WHERE
( (i.involvedemail = e.email_address)
or (replace(lower(e.preferred_name+e.last_name),' ', '') = replace(lower(i.involvedname),' ', ''))
or (replace(lower(e.preferred_name+e.last_name),' ', '') like replace(lower(i.involvedname),' ', '')+'%')
or (replace(lower(left(e.first_name,charindex(' ',e.first_name)-1) + e.last_name),' ', '') = replace(lower(i.involvedname),' ',''))
or (replace(lower(e.employee_name),' ','') = replace(lower(i.involvedname),' ',''))
)
and charindex(' ',e.first_name) > 1
and (i.involvedemail= 'none available' or i.involvedemail is null or i.involvedemail = '')
答案 0 :(得分:4)
你的问题是charindex
函数,为此目的使用locate(代替charindex):
LOCATE(' ',e.first_name)
答案 1 :(得分:0)
很多功能都是一样的。以下是您可以使用的MySQL string functions列表。
答案 2 :(得分:0)
我尝试了 Full Convert Enterprise 取得了巨大的成功。快速,简单,它完成了我的工作。试一试,它可以帮到你。
此外,您最好自己做这件事以确保一切正确而不是依赖第三方工具(另外还有理解两段代码之间差异的好处)。但是,您可以使用SQL to MySQL工具 here 。