易截截图软件、单文件、免安装、纯绿色、仅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 Server 2005 默认sa无法登陆

使用SQL Server身份验证登录时报错:
无法连接到.\SQLEXPRESS.
Additional information:
用户'sa'登录失败。该用户与可信SQL Server 连接无关联。(microsoft SQL Server,Error:18452))
------------------
下面是映射时报的错:
创建对于用户“sa”失败。(microsoft.sqlServer.express.smo)
Additional ......

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

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

安装SQL 2000挂起的解决办法

今天安装sql2000,老是出挂起的错误。所以找了找看见了这个方法。
原帖地址:http://hi.baidu.com/xpyi/blog/item/fa1fd3af254d32f2fbed500d.html
步骤是:
1)添加/删除程序中彻底删除sql server。
2)将没有删除的sql server目录也删除掉。
3)打开注册表编辑器,在HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\ ......

捕获Sql异常

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

Oracle中如何用一条SQL快速生成10万条测试数据

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