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

求个sql截取字符然后比较剩余部分大小的语句.
SELECT   MAX(SUBSTRING(planGroupid,   14,   LEN(planGroupid)   -   13))   AS   planGroupid   FROM   PlanGroup   WHERE   (planGroupid   LIKE   '%20070524% ')

但是如果JSJSB200705249和JSJSB2007052410   为什么比较出的是9而不是10呢
我要怎么才能取到合适的长度呢?谢谢啦```

------解决方案--------------------
用Convert 转化成int 类型就可以了
9 和10 比较 如果按照字符类型比较 肯定是 9 大
------解决方案--------------------
try
SELECT MAX(CAST(SUBSTRING(planGroupid, 14, LEN(planGroupid) - 13) AS INT)) AS planGroupid FROM PlanGroup WHERE (planGroupid LIKE '%20070524% ')
------解决方案--------------------
SELECT MAX(cast(SUBSTRING(planGroupid, 6, LEN(planGroupid) - 5) as int) AS planGroupid FROM PlanGroup WHERE (planGroupid LIKE '%20070524% ')