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


相关文档:

ASP.NET防SQL注入脚本程序 v2.0

public class SqlCheck
{
public SqlCheck()
{
//
// TODO: 在此处添加构造函数逻辑
//
}

public SqlConnection oconn()
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["StudyConnectionString"] ......

SQL Server 2005 默认sa无法登陆

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

ibatis中直执行sql,返回存储Map的List类型

ibatis作为一个轻量级的orm工具现在非常流行,我在使用中发现,有时仅仅希望返回一个类型为map的list就可以了,
比如简单的查询统计之类的,没有必要定义太多的pojo,因此想能不能在ibatis中直接传入sql语句来执行,然后返回map呢?
从网上搜了一下,还真有,实验成功后总结一下,大家共同进步。 其实很简单,就 ......

SQL Server中的约束条件

1.默认约束:定义该列未输入值时应该具有的默认值
SQL-------alter table 表名 add constraint dt_列名 default 默认值 for 列名
2.空值约束:定义该列是否允许为空值
SQL-------定义表的时候在对应列列数据类型后面添加not null
3.检查约束:又叫check约束,用来限制列的取值,它根据定义的逻辑表达式来强制域的完整性 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号