一次編程實踐[ASP+MSSQL]
來源:互聯網
上載者:User
本人工作單位是一家橡塑產品製造企業,05年2月單位領導要求我開發一個生產流程資料核對錶,用來稽核流程資料的準確性,其報表基本原理如下:
後續工序今日正品數 + 後續工序今日廢品數 = 本工序今日正品數 + 本工序今日留存數 - 本工序昨日留存數
瞭解了原理後馬上開工,第一次考慮用暫存資料表:
select distinct LEFT(productid, 4) + '00' as productid into #productid from yuancaiFlow_view
where productiondate = '2004-3-1'
and productid like '01____'
go
select a.productid,
b.productname,
isnull(hj.GoodQty, 0) as hj_good,
isnull(hjtoday.qty, 0) as hj_today,
isnull(hjyesterday.qty, 0) hj_yesterday,
isnull(hj.GoodQty, 0) - isnull(hjtoday.qty, 0) + isnull(hjyesterday.qty, 0) - isnull(sx.GoodQty, 0) - isnull(sx.BadQty, 0) as hj_difference,
isnull(sx.GoodQty, 0) as sx_good,
isnull(sx.BadQty, 0) as sx_bad,
isnull(sxtoday.qty, 0) as sx_today,
isnull(sxyesterday.qty, 0) sx_yesterday,
isnull(sx.GoodQty, 0) - isnull(sxtoday.qty, 0) + isnull(sxyesterday.qty, 0) - isnull(jt.GoodQty, 0) - isnull(jt.BadQty, 0) as sx_difference,
isnull(jt.GoodQty, 0) as jt_good,
isnull(jt.BadQty, 0) as jt_bad,
isnull(jttoday.qty, 0) as jt_today,
isnull(jtyesterday.qty, 0) jt_yesterday,
isnull(jt.GoodQty, 0) - isnull(jttoday.qty, 0) + isnull(jtyesterday.qty, 0) - isnull(ph.GoodQty, 0) - isnull(ph.BadQty, 0) as jt_difference,