日期:2014-05-18  浏览次数:20573 次

删除OUTCELL和INCELL中的-*和-*部分
DATE PERIOD EXCHID OUTCELL INCELL
120614 18001900 XCBSC1R12 XC101A- J-XC101B
120614 18001900 XCBSC1R12 XC101A-L -XC101C
120614 18001900 XCBSC1R12 XC101A- -XC104B
120614 18001900 XCBSC1R12 XC101A-X -XC106A
120614 18001900 XCBSC1R12 XC101A- -XC106C
120614 18001900 XCBSC1R12 XC101A- Y-XC111A
120614 18001900 XCBSC1R12 XC101A- -XC111B
120614 18001900 XCBSC1R12 XC101A- -XC111C
120614 18001900 XCBSC1R12 XC101A- -XC112B
120614 18001900 XCBSC1R12 XC101A- -XC118B

-----数据样子如上,当然数据量比较大,每天都有几万行。麻烦删除outcell的包含“-”和后面所有的字符,删除incell的前面“-”和之前的所有字符

求SQL语句

------解决方案--------------------
SQL code
update tb set outcell=left(outcell,charindex('-',outcell)-1),
incell=right(incell,charindex('-',incell)-1)

------解决方案--------------------
SQL code
update yourtable set outcell = substring(outcell, 0, charindex('-', outcell)), incell = substring(incell, charindex('-', incell) + 1, len(incell))