34,837
社区成员




declare @a table (
id int,
num int
)
insert into @a
select 1,100
union all select 2,200
union all select 3,400
declare @b table (
id int,
num2 int
)
insert into @b
select 1,50
union all select 2,80
union all select 3,110
--下面写法就会报错
update @a set @a.num=@a.num-@b.num2
from @a inner join @b on (@a.[id]=@b.[id])
--写面下列写法就正确,不知为什么,必须另外指定别名才行
update a set a.num=a.num-b.num2
from @a a inner join @b b on (a.[id]=b.[id])
declare @a table (
id int,
num int
)
insert into @a
select 1,100
union all select 2,200
union all select 3,400
declare @b table (
id int,
num2 int
)
insert into @b
select 1,50
union all select 2,80
union all select 3,110
--下面写法就会报错
update @a set @a.num=@a.num-@b.num2
from @a inner join @b on (@a.[id]=@b.[id])
--写面下列写法就正确,不知为什么,必须另外指定别名才行
update a set a.num=a.num-b.num2
from @a a inner join @b b on (a.[id]=b.[id])
declare @a table (
id int,
num int
)
insert into @a
select 1,100
union all select 2,200
union all select 3,400
declare @b table (
id int,
num2 int
)
insert into @b
select 1,50
union all select 2,80
union all select 3,110
--下面写法就会报错
update @a set @a.num=@a.num-@b.num2
from @a inner join @b on (@a.[id]=@b.[id])
--写面下列写法就正确,不知为什么,必须另外指定别名才行
update a set a.num=a.num-b.num2
from @a a inner join @b b on (a.[id]=b.[id])
declare @a table (
id int,
num int
)
insert into @a
select 1,100
union all select 2,200
union all select 3,400
declare @b table (
id int,
num2 int
)
insert into @b
select 1,50
union all select 2,80
union all select 3,110
--下面写法就会报错
update @a set @a.num=@a.num-@b.num2
from @a inner join @b on (@a.[id]=@b.[id])
--写面下列写法就正确,不知为什么,必须另外指定别名才行
update a set a.num=a.num-b.num2
from @a a inner join @b b on (a.[id]=b.[id])