CREATE proc [dbo].[As_Proc_GetPlanDetail]
(
@ids varchar(max)--
)
as
create table #temp
(
dept varchar(100),
sorttitle varchar(200),
title varchar(200),
spec varchar(50),
model varchar(50),
budget decimal(18,2),
amount int,
sgamount int,
htamount int,
ysamount int,
fenfamount int
)
declare @did varchar(32)
declare @sorttitle varchar(200)
declare @title varchar(200)
declare @spec varchar(50)
declare @model varchar(50)
declare @budget decimal(18,2)
declare @amount int
declare @sgamount int
declare @htamount int
declare @ysamount int--验收数量
declare @fenfamount int--分发数量
declare cursor1 cursor for
select rowid,dbo.clip(ypdept,':',1) from As_year_plan where Charindex(rowid,@ids,0)>0 union select rowid,dbo.clip(department,':',1) from As_assets_requisition where Charindex(rowid,@ids,0)>0 -----------------------------------------------
控制计划
declare @rowid varchar(32)
declare @dept varchar(100)
open cursor1
fetch next from cursor1 into @rowid,@dept
begin
declare cursor2 cursor for select a.rowid, b.sorttitle,a.title,a.spec,a.model,a.budget,a.amount from As_assts_planDetai a left join As_assetsSort b on a.sortId=b.rowid whereplanID=@rowid
open cursor2
fetch next from cursor2 into @did, @sorttitle, @title,@spec, @model ,@budget ,@amount
while @@fetch_status=0
begin
select @sgamount= isnull(sum(a.amount),0) from As_assets_buyDetail a inner join As_assets_buy b on a.buyId=b.rowid wherea.planId=@didand b.state=1
--print @did
select @htamount= isnull(sum(a.amount),0) from As_contract_detail a inner join As_stock_contract b on a.contId=b.rowid where b.state=1 and a.bydetId in(
select c.rowid from As_assets_buyDetail c inner join As_assets_buy d on c.buyId=d.rowid wherec.planId=@didand d.state=1)
---验收数量
select @ysamount=count(1) from As_AssetsInfo a inner join As_contract_detail b on a. contractId=b.rowid where b.bydetId in(select rowid from As_assets_buyDetail whereplanId=@did)
--分发数量
select @fenfamount=count(1) from As_AssetsInfo a inner join As_contract_detail b on a. contractId=b.rowid where b.bydetId in(select rowid from As_assets_buyDetail whereplanId=@did) and a.drawState=1
insert into #temp(dept, sorttitle, title , spec, model , budget ,amount,sgamount,htamount, ysamount,fenfamount) values(@dept,@sorttitle, @title , @spec, @model , @budget ,@amount,@sgamount,@htamount,@ysamount,@fenfamount)
fetch next from cursor2 into @did, @sorttitle, @title,@spec, @model ,@budget ,@amount
end
close cursor2 --关闭游标
deallocate cursor2
fetch next from cursor1 into @rowid,@dept
end
close cursor1 --关闭游标
deallocate cursor1 --释放游标
select * from #temp
详细说明
RS.OPEN SQL,CONN,A,B
参数A为设定游标的类型,其取值为: 0 仅向前游标,只能向前浏览记录,不支持
分页、Recordset、BookMark
1 键集游标,其他用户对记录所做的修改将反映到记录集中,但其他用户增加或删除记录不会反映到记录集中。支持
分页、Recordset、BookMark
2
动态游标功能最强,但耗资源也最多。用户对记录所做的修改,增加或删除记录都将反映到记录集中。支持全功能浏览。
3
静态游标,只是数据的一个
快照,用户对记录所做的修改,增加或删除记录都不会反映到记录集中。支持向前或向后移动
1 锁定类型,默认的,只读,不能作任何修改
2 当编辑时立即锁定记录,最安全的方式
3 只有在调用Update方法时才锁定
记录集,而在此前的其他操作仍可对当前记录进行更改、插入和删除等
4 当编辑时记录不会被锁定,而更改、插入和删除是在
批处理方式下完成的
打开数据
记录集方法其实不止一种,但是我们用的最多的就是
rs.open sql,1,1的方法,可是后面的数字参数很多人不解其意,下面我们来介绍一下。
其实open方法后面有多个参数
CursorType LockType CommandType
比如 rs.open sql,1,1
也可以写成
rs.cursorType = 1
rs.LockType = 1
rs.open sql
其中CursorType代表从一个表或者一个SQL查询结果返回的记录。
这个参数有四个值分别是:
adOpenForwardOnly 表示只允许在
记录集内的记录间往前移动。这个是
缺省值。
adOpenKeyset 反映由其它用户所做的对记录的改变或者删除动作,但并不反映由其它用户做作的添加新记录的动作。
adOpenDynamic 反映由其它用户所做的对记录的改变或者删除动作,包括添加的新记录
adOpenStatic 不反映其它用户对记录所做的修改,添加,删除动作。
这四个值VBSCRIPT预定义位
adOpenForwardOnly = 0
adOpenKeyset = 1
adOpenDynamic = 2
adOpenStatic = 3
lockType 表示当打开记录集时,数据提供者用于锁定
数据库的类型:
adLockReadOnly 数据不能改变,这是
缺省值!
adLockPessimistic 数据提供者在开始编辑数据的时候锁定记录
adLockOptimistic 仅当调用update方法时,数据提供者锁定记录
adLockBatchOptimistic 用于
批处理修改
他们的常量值定义分别是:
adLockReadOnly = 1
adLockPessimistic = 2
adLockOptimistic = 3
adLockBatchOptimistic = 4
rs.open sql,conn,1,1 读取记录 select
rs.open sql,conn,1,3 只更新记录最好 update
rs.open sql,conn,2,3 插入和删除最好 insert delete