当前位置: 代码迷 >> Sql Server >> 截取字符解决办法
  详细解决方案

截取字符解决办法

热度:56   发布时间:2016-04-27 12:52:33.0
截取字符
请问一下表A:
ID comment 
1 12*13
2 124*3
3 ASD*4R
4 23D
.....

规则,若有*,截取*前面的数值,若没有,只需带出原有的数值

------解决方案--------------------
SQL code
declare @T table (ID int,comment varchar(6))insert into @Tselect 1,'12*13' union allselect 2,'124*3' union allselect 3,'ASD*4R' union allselect 4,'23D'select left(comment+'*',charindex('*',comment+'*')-1) from @T/*12124ASD23D*/
  相关解决方案