2014-10-28 94 views

回答

2

你可以这样做:

select left(str, charindex('@', str) - 1) 

注:如果字符不存在,这将返回一个错误。所以,你可能想:

select (case when str like '%@%' then left(str, charindex('@', str) - 1) end) 

编辑:

如果您正在使用Netezza公司,你可能需要使用substring()而不是left()。 Postgres的现在支持left(),但没有当Netezza公司开始使用它:

select (case when str like '%@%' then substring(str from 1 for charindex('@', str) - 1) end) 
+0

谢谢戈登。我收到一个错误'左侧关键字附近的语法错误'。 – user3438791 2014-10-30 14:37:38