分享
 
 
 

一次编程实践[ASP+MSSQL]

王朝asp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

本人工作单位是一家橡塑产品制造企业,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,

isnull(ph.GoodQty, 0) as ph_good,

isnull(ph.BadQty, 0) as ph_bad,

isnull(phtoday.qty, 0) as ph_today,

isnull(phyesterday.qty, 0) ph_yesterday,

isnull(ph.GoodQty, 0) - isnull(phtoday.qty, 0) + isnull(phyesterday.qty, 0) - isnull(zj.GoodQty, 0) - isnull(zj.BadQty, 0) as ph_difference,

isnull(zj.GoodQty, 0) as zj_good,

isnull(zj.BadQty, 0) as zj_bad

from #productid as a,

finishedproduct as b,

yuancaiFlow_view as hj,

basflowsubsistence as hjtoday,

basflowsubsistence as hjyesterday,

yuancaiFlow_view as sx,

basflowsubsistence as sxtoday,

basflowsubsistence as sxyesterday,

yuancaiFlow_view as jt,

basflowsubsistence as jttoday,

basflowsubsistence as jtyesterday,

yuancaiFlow_view as ph,

basflowsubsistence as phtoday,

basflowsubsistence as phyesterday,

yuancaiFlow_view as zj

where a.productid = b.productid

--hj

and hj.productiondate = '2004-3-1'

and left(a.productid, 4) *= left(hj.productid, 4)

and hj.productid like '____06'

and left(a.productid, 4) + '06' *= hjtoday.productid

and hjtoday.checkdate = '2004-3-1'

and left(a.productid, 4) + '06' *= hjyesterday.productid

and hjyesterday.checkdate = '2004-2-29'

--sx

and sx.productiondate = '2004-3-1'

and left(a.productid, 4) *= left(sx.productid, 4)

and sx.productid like '____08'

and left(a.productid, 4) + '08' *= sxtoday.productid

and sxtoday.checkdate = '2004-3-1'

and left(a.productid, 4) + '08' *= sxyesterday.productid

and sxyesterday.checkdate = '2004-2-29'

--jt

and jt.productiondate = '2004-3-1'

and left(a.productid, 4) *= left(jt.productid, 4)

and jt.productid like '____07'

and left(a.productid, 4) + '07' *= jttoday.productid

and jttoday.checkdate = '2004-3-1'

and left(a.productid, 4) + '07' *= jtyesterday.productid

and jtyesterday.checkdate = '2004-2-29'

--ph

and ph.productiondate = '2004-3-1'

and left(a.productid, 4) *= left(ph.productid, 4)

and ph.productid like '____09'

and left(a.productid, 4) + '09' *= phtoday.productid

and phtoday.checkdate = '2004-3-1'

and left(a.productid, 4) + '09' *= phyesterday.productid

and phyesterday.checkdate = '2004-2-29'

--zj

and zj.productiondate = '2004-3-1'

and left(a.productid, 4) *= left(zj.productid, 4)

and zj.productid like '01__11'

go

drop table #productid

go

准备用ASP呈现报表,结果ASP端的Recordset老提示出错。只好改用函数:

-- =============================================

-- Create table function (TF)

-- =============================================

IF EXISTS (SELECT *

FROM sysobjects

WHERE name = N'fn_GetGLSubsistenceList')

DROP FUNCTION fn_GetGLSubsistenceList

GO

CREATE FUNCTION fn_GetGLSubsistenceList

(@CheckDate smalldatetime)

RETURNS @FlowSubsistenceList TABLE

(ProductID nvarchar(6),

ProductName nvarchar(32),

HJGoodQty real,

HJTodayQty real,

HJYesterdayQty real,

HJDefference real,

SXGoodQty real,

SXBadQty real,

SXTodayQty real,

SXYesterdayQty real,

SXDefference real,

JTGoodQty real,

JTBadQty real,

JTTodayQty real,

JTYesterdayQty real,

JTDefference real,

PHGoodQty real,

PHBadQty real,

PHTodayQty real,

PHYesterdayQty real,

PHDefference real,

ZJGoodQty real,

ZJBadQty real)

AS

BEGIN

DECLARE @ProductIDList TABLE

(ProductID nvarchar(6))

DECLARE @YesterdayOfCheckDate smalldatetime

SET @YesterdayOfCheckDate = DATEADD(day, -1, @CheckDate)

--保存该日生产的产品ID号

INSERT @ProductIDList

select distinct LEFT(productid, 4) + '00' as productid from yuancaiFlow_view

where productiondate = @CheckDate

and productid like '01____'

--正常工序为hj->sx->jt->ph->zj

INSERT @FlowSubsistenceList

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,

0 - (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,

0 - (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,

0 - (isnull(jt.GoodQty, 0) - isnull(jttoday.qty, 0) + isnull(jtyesterday.qty, 0) - isnull(ph.GoodQty, 0) - isnull(ph.BadQty, 0)) as jt_difference,

isnull(ph.GoodQty, 0) as ph_good,

isnull(ph.BadQty, 0) as ph_bad,

isnull(phtoday.qty, 0) as ph_today,

isnull(phyesterday.qty, 0) ph_yesterday,

0 - (isnull(ph.GoodQty, 0) - isnull(phtoday.qty, 0) + isnull(phyesterday.qty, 0) - isnull(zj.GoodQty, 0) - isnull(zj.BadQty, 0)) as ph_difference,

isnull(zj.GoodQty, 0) as zj_good,

isnull(zj.BadQty, 0) as zj_bad

from @ProductIDList as a,

finishedproduct as b,

yuancaiFlow_view as hj,

basflowsubsistence as hjtoday,

basflowsubsistence as hjyesterday,

yuancaiFlow_view as sx,

basflowsubsistence as sxtoday,

basflowsubsistence as sxyesterday,

yuancaiFlow_view as jt,

basflowsubsistence as jttoday,

basflowsubsistence as jtyesterday,

yuancaiFlow_view as ph,

basflowsubsistence as phtoday,

basflowsubsistence as phyesterday,

yuancaiFlow_view as zj

where a.productid = b.productid

--hj

and hj.productiondate = @CheckDate

and left(a.productid, 4) *= left(hj.productid, 4)

and hj.productid like '____06'

and left(a.productid, 4) + '06' *= hjtoday.productid

and hjtoday.checkdate = @CheckDate

and left(a.productid, 4) + '06' *= hjyesterday.productid

and hjyesterday.checkdate = @YesterdayOfCheckDate

--sx

and sx.productiondate = @CheckDate

and left(a.productid, 4) *= left(sx.productid, 4)

and sx.productid like '____08'

and left(a.productid, 4) + '08' *= sxtoday.productid

and sxtoday.checkdate = @CheckDate

and left(a.productid, 4) + '08' *= sxyesterday.productid

and sxyesterday.checkdate = @YesterdayOfCheckDate

--jt

and jt.productiondate = @CheckDate

and left(a.productid, 4) *= left(jt.productid, 4)

and jt.productid like '____07'

and left(a.productid, 4) + '07' *= jttoday.productid

and jttoday.checkdate = @CheckDate

and left(a.productid, 4) + '07' *= jtyesterday.productid

and jtyesterday.checkdate = @YesterdayOfCheckDate

--ph

and ph.productiondate = @CheckDate

and left(a.productid, 4) *= left(ph.productid, 4)

and ph.productid like '____09'

and left(a.productid, 4) + '09' *= phtoday.productid

and phtoday.checkdate = @CheckDate

and left(a.productid, 4) + '09' *= phyesterday.productid

and phyesterday.checkdate = @YesterdayOfCheckDate

--zj

and zj.productiondate = @CheckDate

and left(a.productid, 4) *= left(zj.productid, 4)

and zj.productid like '01__11'

RETURN

END

GO

ASP端与SQL端意外地解耦合了:

Dim rsCheckList

Set rsCheckList = Server.CreateObject("ADODB.Recordset")

rsCheckList.ActiveConnection = oConn

rsCheckList.Open"select * from dbo.fn_GetGLSubsistenceList('"&datCheckDate&"')"

这次编程实践让我得到一个ASP开发的新思路:

用视图+函数封装数据库端,ASP端只调用函数,这样做最大的好处是平台移植更加方便了,并且对ASP程序员的数据库知识要求也降低了。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有