以下是引用lin_hailun在2012-11-14 15:34:00的发言:
截取银行的统计,但代价不是一般的大,楼主,三思哦。
select 科目名称, sum(金额) as 金额 from
(select
iif(Instr(科目名称, '\') = 0, left(科目名称, len(科目名称)), iif(InStr(Right(科目名称, cint(Len(科目名称) - Instr(科目名称, '\'))), '\') = 0,
left(科目名称, len(科目名称)), left(科目名称, cint(Instr(科目名称, '\') + InStr(Right(科目名称, cint(Len(科目名称) - Instr(科目名称, '\'))), '\') - 1)))) As 科目名称, 金额
from {表A})
group by 科目名称
用SQL作为外部数据源,用下列代码,提示有错误。
select 科目名称, sum(金额) as 金额 from
(select
Case when CharIndex(科目名称, '\') = 0 then left(科目名称, len(科目名称)) else case when CharIndex(Right(科目名称, Ceiling(Len(科目名称) - CharIndex(科目名称, '\'))), '\') = 0 then left(科目名称, len(科目名称)) else left(科目名称, Ceiling(CharIndex(科目名称, '\') + CharIndex(Right(科目名称, Ceiling(Len(科目名称) - CharIndex(科目名称, '\'))), '\') - 1)) end end As 科目名称, 金额
from {表A})
group by 科目名称