易截截图软件、单文件、免安装、纯绿色、仅160KB

sql 查询先进先出

declare @tb3 table (商品编号 nvarchar(10),批次号 nvarchar(10),库存数量 int,出库数量 int)
declare @tb1 table (商品编号 nvarchar(10),批次号 nvarchar(10),库存数量 int)
insert into @tb1 select '0001','090801',200
      union all  select '0001','090501',50
      union all  select '0002','090101',30
      union all  select '0002','090701',200
declare @tb2 table (商品编号 nvarchar(10),订货数量 int)
insert into @tb2 select '0001',60
      union all  select '0002',20
--declare @var int
declare c_sor cursor
for
select 商品编号,sum(订货数量)订货数量 from @tb2 group by 商品编号
declare @bh nvarchar(10), @dh int,@bh1 nvarchar(10),@pc nvarchar(10), @kc int
open  c_sor
fetch next from c_sor into @bh,@dh
while @@fetch_status=0
begin
declare sor cursor for select * from @tb1 where 商品编号=@bh order by 批次号
open sor
fetch next from sor into @bh1,@pc,@kc
insert into @tb3 select @bh, @pc,@kc,case when @kc>@dh then @dh else @kc end
set @dh=@dh-@kc
while @dh>0
 begin
 fetch next from sor into @bh1,@pc,@kc
 insert into @tb3 select @bh, @pc,@kc,case when @kc>=@dh then @dh else @kc end
 set @dh=@dh-@kc
 end
close sor
deallocate sor
fetch next from c_sor into @bh,@dh
end
close c_sor
deallocate c_sor
select * from @tb3  order by 商品编号,批次号 desc


相关文档:

航空公司管理系统(VC++ 与SQL 2005)

系统环境:Windows 7
软件环境:Visual C++ 2008 SP1 +SQL Server 2005
本次目的:编写一个航空管理系统
      这是数据库课程设计的成果,虽然成绩不佳,但是作为我用VC++ 以来编写的最大程序还是传到网上,以供参考。用VC++ 做数据库设计并不容易,但也不是不可能。以下是我的程序界面,后面 ......

asp.net如何连接sql server2000数据库

★Asp.net如何连接SQL Server2000数据库★
 
大家好,以下是有关ASP.net连接SQL Server2000数据库的例程,
在这里和大家分享一下:
Asp.net连接SQL Server2000数据库例程详解: 
<%@ Import Namespace="System.Data" %> 
<%@ Import NameSp ......

ADO.NET中的sql连接

using System.Data;            // Use ADO.NET namespace
using System.Data.SqlClient;  
 SqlConnection thisConnection = new SqlConnection(
      &nbs ......

捕获Sql异常

帮助里的,语法:
BEGIN TRY
    { sql_statement | statement_block }
END TRY
BEGIN CATCH
          [ { sql_statement | statement_block } ]
END CATCH
[ ; ]
异常部分:
在 CATCH 块的作用域内,可以使用以下系统函数来获取导致 CATCH 块执行的错误消息:
ERROR ......

如何清除SQL server日志

  前几天做一个关于数据表优化的程序,由于数据库里面的字段的关系非常复杂,操作起来比较麻烦,刚用的时候还好,运行时间一长,生成的事务日志很大,占用了10几G,磁盘都快用完了。
    到网上搜了一下,方法下面两种:
    1.分离数据库,直接删除事务日志文件,再附加数据库,系统 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号