呵呵,18天"晕"还算是个正常人(不晕大概是天才了),我的经验是精看『编程基础』及『FoxTable编程』两章,引用狐狸爸爸的话:》要反复看,细致看,多实践,只有基础打好了,才能融会贯通,才能在开发过程中做到游刃有余。
本人从没学过SQL,只是用过易表,试用FoxTable时间不长,如今用SQL可以捣鼓出土建材料分析的SQL语句了:
Dim cmd As New SQLCommand
Dim SQL As String
SQL = "select h.材料編號,h.材料名稱,h.單位, h.數量,t.商品砼 from("
SQL = SQL & "select Min(序號) as 序號,材料編號,材料名稱,max(單位) as 單位,"
SQL = SQL & "round(sum(數量),4) as 數量 from(select * from(select y.序號,d.deno as 定額編號,"
SQL = SQL & "d.項目名稱,iif(d.clno like 'p_%' and y.商品砼 =0,'',d.clno) as 材料編號,d.clmq as 材料名稱,"
SQL = SQL & "d.單位,d.clsl = null as 配合量,d.clsl as 定額用量,y.數量 as 預算量,round(d.clsl*y.數量,4) as 數量, "
SQL = SQL & "y.商品砼 from {定額費} d inner join {預算書} y on d.deno = y.deno) where 材料編號 > '' union all"
SQL = SQL & " select b.序號,a.dno as 定額編號,a.pbmq as 項目名稱,a.clno as 材料編號,a.clmq as 材料名稱,"
SQL = SQL & "a.cldw as 單位,a.clsl as 配合量,b.定額用量,b.預算量,round(a.clsl*b.數量,4) as 數量, b.商品砼"
SQL = SQL & " from{配合比} a inner join(select * from(select y.序號,d.deno ,d.項目名稱,d.clno,d.clmq,d.單位,"
SQL = SQL & "d.clsl = null as 配合量,d.clsl as 定額用量,y.數量 as 預算量,round(d.clsl*y.數量,4) as 數量, y.商品砼"
SQL = SQL & " from {定額費} d inner join {預算書} y on d.deno = y.deno) where clno like 'p_%' and 商品砼 = 0) b"
SQL = SQL & " on b.clno = a.dno) group by 材料編號,材料名稱) h left join {預算書} t on h.序號 = t.序號"
cmd.CommandText = SQL
Tables("材料分析_Table1").DataSource = cmd.ExecuteReader()
Tables("材料分析_Table1").AutoSizeCols