--更新 declare @产品代码 char(4),@库存数量 int select @产品代码='Q346',@库存数量=10declare @a int update 表 set @a=@库存数量+本次购入数量 ,库存数量=@a,@库存数量=@a from 表 a where 产品代码=@产品代码
--测试--测试数据 create table 表(票单号 char(6),开票时间 datetime,本次购入数量 int,库存数量 int,产品代码 char(4)) insert 表 select 'T00134','2004-1-1',10,NULL,'Q346' union all select 'T02154','2004-5-4',20,NULL,'Q346' union all select 'T00542','2004-6-4',10,NULL,'Q346' union all select 'T00124','2004-6-7',30,NULL,'Q346' go--更新 declare @产品代码 char(4),@库存数量 int select @产品代码='Q346',@库存数量=10declare @a int update 表 set @a=@库存数量+本次购入数量 ,库存数量=@a,@库存数量=@a from 表 a where 产品代码=@产品代码--显示更新结果 select * from 表 go--删除测试 drop table 表/*--测试结果 票单号 开票时间 本次购入数量 库存数量 产品代码 ------ -------------------------- ----------- ----------- -------- T00134 2004-01-01 00:00:00.000 10 20 Q346 T02154 2004-05-04 00:00:00.000 20 40 Q346 T00542 2004-06-04 00:00:00.000 10 50 Q346 T00124 2004-06-07 00:00:00.000 30 80 Q346(所影响的行数为 4 行)--*/
T02154 2004-5-4 20 Q346
T00542 2004-6-4 10 Q346
T00124 2004-6-7 30 Q346需要更新库存数量一列,为
票单号 开票时间 本次购入数量 库存数量 产品代码 T00134 2004-1-1 10 20(需要加上已有库存10) Q346
T02154 2004-5-4 20 40 Q346
T00542 2004-6-4 10 50 Q346
T00124 2004-6-7 30 80 Q346
declare @产品代码 char(4),@库存数量 int
select @产品代码='Q346',@库存数量=10declare @a int
update 表 set @a=@库存数量+本次购入数量
,库存数量=@a,@库存数量=@a
from 表 a
where 产品代码=@产品代码
create table 表(票单号 char(6),开票时间 datetime,本次购入数量 int,库存数量 int,产品代码 char(4))
insert 表 select 'T00134','2004-1-1',10,NULL,'Q346'
union all select 'T02154','2004-5-4',20,NULL,'Q346'
union all select 'T00542','2004-6-4',10,NULL,'Q346'
union all select 'T00124','2004-6-7',30,NULL,'Q346'
go--更新
declare @产品代码 char(4),@库存数量 int
select @产品代码='Q346',@库存数量=10declare @a int
update 表 set @a=@库存数量+本次购入数量
,库存数量=@a,@库存数量=@a
from 表 a
where 产品代码=@产品代码--显示更新结果
select * from 表
go--删除测试
drop table 表/*--测试结果
票单号 开票时间 本次购入数量 库存数量 产品代码
------ -------------------------- ----------- ----------- --------
T00134 2004-01-01 00:00:00.000 10 20 Q346
T02154 2004-05-04 00:00:00.000 20 40 Q346
T00542 2004-06-04 00:00:00.000 10 50 Q346
T00124 2004-06-07 00:00:00.000 30 80 Q346(所影响的行数为 4 行)--*/
昨天调试存储过程的时候,提示我下面的信息:
如果您用“本地系统帐户”登录而SQL Server配置为作为服务运行,则SP调试可能不会正常工作。
可以打开Event Viwer以查看详细信息 要继续吗? 上面就是提示。
如果点 是,则调试没有断点了
结帖代替语言吧。