select abstractInfo, substring(brandName,1,charindex('-',brandName)-1) brand,brandname,sum(num) total from ( select id, brandname ,brandBatch,status,abstractInfo,inStock,nowStock,outStock,createDateTime,cargoSpace, (case when abstractInfo='入库' then inStock when abstractInfo='出库' then outStock else '' end) num from dbo.inOutStockInfo where abstractInfo='${type}' and status <>'营销物资' and datediff(year,createDateTime,getdate())=0 ) a group by abstractInfo,substring(brandName,1,charindex('-',brandName)-1),brandname 把charindex('-',brandName)-1 改为10,OK SQLserver 是否对 substring 函数长度做限制? substring(brandName,1,charindex('-',brandName)-1) 如何减少嵌套层数? |