0

嘿伙计们,我用我出色的 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 = '')
4

3 回答 3

4

您的问题是charindex功能,为此目的使用定位(代替charindex):

LOCATE(' ',e.first_name)
于 2012-06-25T06:14:23.513 回答
0

很多功能都是一样的。这是您可以使用的MySQL 字符串函数列表。

于 2012-06-25T06:12:43.543 回答
0

我尝试了Full Convert Enterprise,并取得了很大的成功。快速,简单,它完成了我的工作。试一试它可能对你有帮助。

Also, You're probably best off doing this yourself to ensure everything is correct rather than relying on a third party tool (Also the additional benefit of understanding the differences between the two pieces of code). However you could use SQL to MySQL tool available here.

于 2012-06-25T06:18:29.003 回答