以上有点小错,更正如下:
部门应该是固定的,简单一点,假设子公司A只有“工”、“在”、”一“、”中“四个部门。
先得到子公司A的表一:
sql="select 公司,部门,流水号,请购单号,姓名,数量,单价,品名,小计,sum(case 部门 when '工' then 小计 else 0 end) as 工总计,"
sql=sql&"sum(case 部门 when '在' then 小计 else 0 end) as 在总计,sum(case 部门 when '一' then 小计 else 0 end) as 一总计,"
sql=sql&"sum(case 部门 when '中' then 小计 else 0 end) as 中总计 "
sql=sql&"from 表1 Where 公司='A' order by 部门"
rs.open sql,conn,1,3
if not rs.eof then
i=1
depart=""
do while not rs.eof
depart=rs("部门)
if i=1 then
str=str& "<tr><td rowspan=""{$部门流水数}"">"&rs("部门)&"</td><td>"&rs("流水号)"&"</td><td>"&...&"</td>"
str=str&"<td rowspan=""{$部门流水数}"">{$str1}"&"</td></tr>"
else
str=str& "<tr><td>"&rs("流水号")"&"</td><td>"&...&"</td></tr>"
end if
rs.movenext
if rs("部门)"<>depart then
str1=depart&"总计"
str=replace(str,{$str1}, rs(str1))
str=replace(str,{$部门流水数},i)
i=1
else
i=i+1
end if
loop
response.write str
子公司B的表如此类推。
自己再想想把公司列也加进去,再判断一个j就行了。
部门应该是固定的,简单一点,假设子公司A只有“工”、“在”、”一“、”中“四个部门。
先得到子公司A的表一:
sql="select 公司,部门,流水号,请购单号,姓名,数量,单价,品名,小计,sum(case 部门 when '工' then 小计 else 0 end) as 工总计,"
sql=sql&"sum(case 部门 when '在' then 小计 else 0 end) as 在总计,sum(case 部门 when '一' then 小计 else 0 end) as 一总计,"
sql=sql&"sum(case 部门 when '中' then 小计 else 0 end) as 中总计 "
sql=sql&"from 表1 Where 公司='A' order by 部门"
rs.open sql,conn,1,3
if not rs.eof then
i=1
depart=""
do while not rs.eof
depart=rs("部门)
if i=1 then
str=str& "<tr><td rowspan=""{$部门流水数}"">"&rs("部门)&"</td><td>"&rs("流水号)"&"</td><td>"&...&"</td>"
str1=rs("部门")&"总计"
str=str&"<td rowspan=""{$部门流水数}"">"&rs(str1)&"</td></tr>"
else
str=str& "<tr><td>"&rs("流水号")"&"</td><td>"&...&"</td></tr>"
end if
rs.movenext
if rs("部门)"<>depart then
str=replace(str,{$部门流水数},i)
i=1
else
i=i+1
end if
loop
response.write str
子公司B的表如此类推。
自己再想想把公司列也加进去,再判断一个j就行了。
tmp1=""
rs.open "select * from 表1 order by 子公司,部门",conn,1,3
if not rs.eof then
do while not rs.eof
response.write "<tr>"
if rs("子公司")<> tmp1 and tmp1<>"" then
子公司数量=conn.execute("select count(*) from 表1 where 子公司='"&rs("子公司")&"'")(0)
response.write "<td rowspan="&子公司数量&">"&rs("子公司")&"</td>"
tmp1 = rs("子公司")
end if
'以上是输出子公司的思路,部门和总计那两列同理,再次衔套就行
response.write "<td>"&rs("流水号")&"</td>"
response.write "<td>"&rs("请购单号")&"</td>
。。。。。。
。。。。。。
loop
end if
看明白了吗,直接输出就行,就是单元格组合的问题,大概写的,有错误自己判断吧