

下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、sqlserver函數(shù),存儲過程,游標(biāo)以及whileif語句的嵌套使編寫這個存儲過程的主要原因是太懶,不愿意每天往表做數(shù)據(jù),所以就寫了他。不僅僅是學(xué)習(xí),也是的鍛煉。USE oaerpGO/* Object: StoredProcedure dbo.s_Get_AutoYh Script Date: 02/11/2015 17:17:35 */SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO- =- Author: - Create date: - Description: - =ALTER PROCEDURE dbo.s_Get_AutoYhsdtm
2、datetime=null,-開始的時間edtm datetime=null,-結(jié)束的時間DepoID char(10)=null,UserID char(20)=null,type varchar(30)=null,- 影響的數(shù)num int=null outputAS-般藥品養(yǎng)護記錄(ybyh)if (type=ybyh)BEGIN-創(chuàng)建張臨時表select a.* into #tmpyh from dbo.GetGoodsBatchListUnReal(DepoID,) a inner join ggoods b on a.goodsid=b.goodsidleft join gGood
3、sExt c on b.goodsid =c.goodsidwhere a.amount 0and b.catid like 01%and c.storeid !=07order by a.effdatedeclare days int -計算天數(shù)declare count int -統(tǒng)計要養(yǎng)護的數(shù)據(jù)declare Idx intdeclare n int -記錄每天需要插的數(shù)據(jù)declare m int -記錄執(zhí)的天數(shù)declare Doccode varchar(30)declare GoodsID char(10)declare Amount decimal(18,6)declare B
4、atchNo varchar(40)declare EffDate datetimedeclare StockArea char(2)declare Station char(2)declare CheckResult char(2)declare DoMethod char(2)declare MakID char(10)declare MakDtm datetimedeclare MakDtm datetime- 開始和結(jié)束時間的差就是本次需要添加養(yǎng)護記錄天數(shù)set days = datediff(day,sdtm,edtm)if days = 0beginset days = 1end-
5、得到總的記錄數(shù),即當(dāng)前店所有的品種select count = count(*) from #tmpyh-設(shè)置每天的記錄條數(shù),向下取整。set n=floor(count/30)set m=1-開始事務(wù)-begin tranbegin tryset makdtmwhile(days0)begindeclare ybyh cursor global- 定義個游標(biāo)read_onlyfor select goodsid,batchno,effdate,amount from #tmpyhopen ybyh-如果執(zhí)的天數(shù)在輸?shù)臅r間范圍內(nèi)-while(m0)-begin-if not exists(se
6、lect * from zGspyhRecord where goodsid and isnull(batchno,)=isnull(batchno,) and isnull(effdate,)=isnull(effdate,)-beginselect stockarea = case a.otcidwhen 01 then 00when 01 then 00when 02 then 01when 03 then 02endfrom ggoods a where goodsidselect Idx=isnull(max(Idx),0)+1 from zGspyhRecord where-設(shè)置時
7、間和養(yǎng)護員信息set MakID=UserID-select DATEADD(dd,5550,2015-02-12 11:11:13)insert into zGspyhRecord(DocCode, DepoID, Idx, GoodsID, Amount,BatchNo, EffDate, StockArea, Station, CheckResult,DoMethod, MakID, MakDtm,CheID, CheDtm)values(DocCode,DepoID,Idx,GoodsID,Amount,BatchNo,EffDate,stockarea,00,00,03,MakID,
8、MakDtm,null,nset n=n-1-在秒上加上idx序號,作為新的時間的秒set Idx=Idx+1set MakDtm=DATEADD(SS,Idx,MakDtm)print(today had +str(n) )if n=0beginexec s_Get_DocCodeSerial_ByTradeID TradeID=60,depoID=DepoID,DocCode=DocCode outputset MakDtm=DATEADD(DD,1,MakDtm)set days -1set n=floor(count/30)if(days%30=0)beginprint(days:+str(days)breakendend-end- 執(zhí)游標(biāo),獲得數(shù)據(jù),直到讀取所有的數(shù)據(jù)集合fetch next from ybyh into goodsid,batchno,effdate,amount-end-END-set m=m+1 -設(shè)置天數(shù)增加1天-set MakDtm=DATEADD(DD,1,MakDtm)ENDclose ybyh - 關(guān)閉游標(biāo)deall
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 四川外國語大學(xué)成都學(xué)院《園林PSSU》2023-2024學(xué)年第二學(xué)期期末試卷
- 5層知識樹課件
- 幼兒園手指游戲課程研究
- 陽光學(xué)院《航天醫(yī)學(xué)工程概論》2023-2024學(xué)年第二學(xué)期期末試卷
- 2025年福建省福州市第十中學(xué)高三3.20聯(lián)考考試英語試題含解析
- 開封市龍亭區(qū)2025年小學(xué)六年級數(shù)學(xué)畢業(yè)檢測指導(dǎo)卷含解析
- 重慶第二師范學(xué)院《室內(nèi)深化設(shè)計》2023-2024學(xué)年第二學(xué)期期末試卷
- 山東華宇工學(xué)院《機械設(shè)計》2023-2024學(xué)年第二學(xué)期期末試卷
- 浙江省杭州地區(qū)七校聯(lián)考2024-2025學(xué)年高三下學(xué)期第一次統(tǒng)一考試(1月)化學(xué)試題含解析
- 貴州交通職業(yè)技術(shù)學(xué)院《包裝系統(tǒng)設(shè)計》2023-2024學(xué)年第一學(xué)期期末試卷
- 第9課《木蘭詩》教學(xué)設(shè)計 2024-2025學(xué)年統(tǒng)編版語文七年級下冊
- 中央2025年中國日報社及所屬事業(yè)單位招聘5人筆試歷年參考題庫附帶答案詳解
- 2024年成都市新都區(qū)教育局所屬事業(yè)單位招聘中小學(xué)教師筆試真題
- 2025-2030中國露酒行業(yè)市場深度分析及發(fā)展趨勢與投資戰(zhàn)略研究報告
- 生產(chǎn)車間5S管理制度
- 2025年吉林鐵道職業(yè)技術(shù)學(xué)院單招職業(yè)技能測試題庫一套
- 2023學(xué)年杭州市余杭區(qū)七年級語文下學(xué)期期中考試卷附答案解析
- 《道路交通安全法》課件完整版
- 加快形成農(nóng)業(yè)新質(zhì)生產(chǎn)力
- 全國園地、林地、草地分等定級數(shù)據(jù)庫規(guī)范1123
- 護理中醫(yī)新技術(shù)新項目
評論
0/150
提交評論