易截截图软件、单文件、免安装、纯绿色、仅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


相关文档:

【转载.SQL注入原理】SQL注入法攻击一日通

随着B/S模式应用开发的发展,使用这种模式编写应用程序的程序员也越来越多。但是由于程序员的水平及经验也参差不齐,相当大一部分程序员在编写代码的时候,没有对用户输入数据的合法性进行判断,使应用程序存在安全隐患。用户可以提交一段数据库查询代码,根
据程序返回的结果,获得某些他想得知的数据,这就是所谓的S ......

sql server 存储过程里的like函数。

    以string 类型的Name为例
在SQL 语句里: string sql="Name like'%" + Name.Text + "%';
在存储过程里:
    if @Name!=''
begin
 set @strWhere= +'  and Name like '''+'%'+@Name+'%'+''''
end
存储过程中的引号是单引号.
like '''+'%'中间不用+认不 ......

从sql server中导出插入数据的语句

此方法是从一位前辈那里学来的,导语句很方便,只需写清楚表名就行。怕忘了,暂记一下。(sql server 2005试验过)
第一次使用的话,需要建立如下存储过程。代码很长,没关系,直接copy就行。
--------- outputdata 存储过程
 CREATE PROCEDURE dbo.OutputData
@tablename sysname
AS
declare @column va ......

oralce 生成10万条测试数据的sql语句

做数据库开发或管理的人经常要创建大量的测试数据,动不动就需要上万条,如果一条一条的录入,那会浪费大量的时间,本文介绍了Oracle中如何通过一条SQL快速生成大量的测试数据的方法。
产生测试数据的SQL如下:
SQL> select rownum as id,
  2          &nbs ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号