select left(字段名,case when charindex('&',字段名)>0 then charindex('&',字段名)-1 else LEN(字段名) end )
select 省=left(ph_city,charindex('&',ph_city)-1)from Tab_ph where charindex('&',ph_city)>0 union all select 省=ltrim(ph_city) from Tab_ph where charindex('&',ph_city)<=0
换成字段名,
服务器: 消息 536,级别 16,状态 3,行 1
向 substring 函数传递了无效的 length 参数。select 省=left(ph_city,charindex('&',ph_city)-1)from Tab_ph
select left(字段名,case when charindex('&',字段名)>0
then charindex('&',字段名)-1 else LEN(字段名) end )
union all
select 省=ltrim(ph_city) from Tab_ph where charindex('&',ph_city)<=0