SQL语句中截取字符的写法?
比如象 "SN   0352-1995 "这样的字段,我要截取   -   之前的数值,最后值为    "SN   0352 " 
 SQL里怎么写?
------解决方案--------------------用charindex定位 '- ' 
 然后用substring 或left即可
------解决方案--------------------Declare @str Varchar(20) 
 Set @str= 'SN 0352-1995 ' 
 Select @str 
 Select Left(@str,CharIndex( '- ',@str)-1) As 截取后的值 
 ---结果 
 /* 
 --------------------  
 SN 0352-1995   
 (所影响的行数为 1 行)   
 截取后的值                 
 --------------------  
 SN 0352   
 (所影响的行数为 1 行) 
 */
------解决方案--------------------declare @s as varchar(20) 
 set @s =  'SN 0352-1995 '   
 set @s = left(@s,charindex( '- ',@s)-1)   
 print @s   
 /* 
 SN 0352 
 */