update a set s=s-500 where S>500 and S<600 楼上的,这个"s-500" 中的S的值能确定出来吗?如果能他是以什么为标准的?
--测试代码 declare @tb table(int int identity(1,1),s int) insert @tb select 400 union all select 100 union all select 550 union all select 620 union all select 123select * from @tb update @tb set s = s - 500 where s > 500 and s < 600 select * from @tb /* 更新前的数据 nt s ----------- ----------- 1 400 2 100 3 550 4 620 5 123更新后的数据int s ----------- ----------- 1 400 2 100 3 50 4 620 5 123(所影响的行数为 5 行) */
drop table test create TABLE test (a int,b int, c int)insert into test values('100','300','400') insert into test values('200','500','400') insert into test values('300','600','400') insert into test values('400','700','400') insert into test values('500','600','400') insert into test values('600','800','400')create procedure Hd_SP_test( @x int , @y int) AS declare @a int, @b int
declare TempCur scroll cursor for select a,b from test open tempcur fetch first from tempcur into @a, @b
while @@fetch_status =0 begin if (@b>@x) and (@b<@y) update test set b=@b-@x where a=@a fetch next from tempcur into @a, @b end close tempcur deallocate tempcurexec hd_sp_test 500,800______________________________________________(所影响的行数为 1 行) (所影响的行数为 1 行) (所影响的行数为 1 行) 100 300 400 200 500 400 300 100 400 400 200 400 500 100 400 600 800 400
楼上的,这个"s-500" 中的S的值能确定出来吗?如果能他是以什么为标准的?
declare @tb table(int int identity(1,1),s int)
insert @tb
select 400 union all
select 100 union all
select 550 union all
select 620 union all
select 123select * from @tb
update @tb set s = s - 500 where s > 500 and s < 600
select * from @tb
/*
更新前的数据
nt s
----------- -----------
1 400
2 100
3 550
4 620
5 123更新后的数据int s
----------- -----------
1 400
2 100
3 50
4 620
5 123(所影响的行数为 5 行)
*/
drop table test
create TABLE test
(a int,b int, c int)insert into test values('100','300','400')
insert into test values('200','500','400')
insert into test values('300','600','400')
insert into test values('400','700','400')
insert into test values('500','600','400')
insert into test values('600','800','400')create procedure Hd_SP_test(
@x int , @y int)
AS declare @a int, @b int
declare TempCur scroll cursor
for
select a,b from test open tempcur
fetch first from tempcur into @a, @b
while @@fetch_status =0
begin
if (@b>@x) and (@b<@y)
update test set b=@b-@x where a=@a
fetch next from tempcur into @a, @b
end close tempcur
deallocate tempcurexec hd_sp_test 500,800______________________________________________(所影响的行数为 1 行)
(所影响的行数为 1 行)
(所影响的行数为 1 行)
100 300 400
200 500 400
300 100 400
400 200 400
500 100 400
600 800 400