如果我的列包含这些值
"Added by Manu on 31-12-2013 & 12thFeb2014"
"Added by Manu on 01-01-2014 [nx-RP-S]"
"Added by Manu on 8thApril2014 (Pnxs)"
added by Manu on 7thFeb2014 [np1PUNCTnp2]
然后我想要一个只删除此字符串的查询
"Added by Manu on 31-12-2013 & 12thFeb2014"`
"Added by Manu on 01-01-2014 ""
"Added by Manu on 8thApril2014"
"added by Manu on 7thFeb2014 " rest [nx-RP-S],(Pnxs),[np1PUNCTnp2]
分别将在列中。
示例如果原始值为"Added by Manu on 01-01-2014 [nx-RP-S]"
,那么我只想从列中删除"Added by Manu on 01-01-2014"
,如果原始值为"Added by Manu on 31-12-2013 & 01-01-2014"
,则将其设为null
提前致谢。
答案 0 :(得分:0)
这将从[
]中删除该部分 select SUBSTRING_INDEX(your_column, '[', 1) as removedPart from table1
编辑:为了你纠正的要求试试这个:
select CASE WHEN your_column NOT Like '%[%' then 'NULL'
else SUBSTRING_INDEX(your_column, ' ', -1) end as modified from table1
EDIT2:
更新规则使用此:
Update table1
set your_column =
CASE WHEN your_column NOT Like '%[%' then 'NULL'
else SUBSTRING_INDEX(your_column, ' ', -1) end