无法绑定由多个部分组成的标识符,该怎么处理
无法绑定由多个部分组成的标识符
create proc testproductstock2
@dcode varchar(20),
@funcid int,
@model int
as
begin
set nocount on
-------------------------
if @model =1
begin
select * from v_rukutest b
select * from productstock a
update productstock set
stock = isnull(stock,0)+isnull(b.basedigit,0)
where a.factorycode=b.factorycode and a.productcode=b.productcode
and a.storagecode=b.storagecode and a.batchcode=b.batchcode
end
if not exists (select 1 from productstock with (nolock)
where a.factorycode=b.factorycode and b.productcode=a.productcode
and b.storagecode=a.storagecode and b.batchcode=a.batchcode)
insert into productstock (factorycode,storagecode,productcode,batchcode,stock)
select factorycode,storagecode,productcode,batchcode,basedigit
from v_rukutest where dcode=@dcode
return
end
------解决方案--------------------
try this,
------解决方案--------------------
------解决方案--------------------
因为原写法中a,b表没有关联关系.
------解决方案--------------------
因为你在语句中引用了表xx的字段,但是没有在语句中写xx表,比如你是这么写的:
select *
from a
where a.id = xx.id
而应该写成:
select *
from a , xx
where a.id = xx.id
你应用了xx表的id字段,所以必须要在from 中写上 xx
------解决方案--------------------
具体要看2个表的关联关系是否正确,是否关联的结果为空集,空集即没有更新喔.
create proc testproductstock2
@dcode varchar(20),
@funcid int,
@model int
as
begin
set nocount on
-------------------------
if @model =1
begin
select * from v_rukutest b
select * from productstock a
update productstock set
stock = isnull(stock,0)+isnull(b.basedigit,0)
where a.factorycode=b.factorycode and a.productcode=b.productcode
and a.storagecode=b.storagecode and a.batchcode=b.batchcode
end
if not exists (select 1 from productstock with (nolock)
where a.factorycode=b.factorycode and b.productcode=a.productcode
and b.storagecode=a.storagecode and b.batchcode=a.batchcode)
insert into productstock (factorycode,storagecode,productcode,batchcode,stock)
select factorycode,storagecode,productcode,batchcode,basedigit
from v_rukutest where dcode=@dcode
return
end
------解决方案--------------------
try this,
create proc testproductstock2
(@dcode varchar(20),
@funcid int,
@model int)
as
begin
set nocount on
if @model=1
begin
select * from v_rukutest b
select * from productstock a
update a
set stock=isnull(stock,0)+isnull(b.basedigit,0)
from productstock a,v_rukutest b
where a.factorycode=b.factorycode and a.productcode=b.productcode
and a.storagecode=b.storagecode and a.batchcode=b.batchcode
end
if not exists (select 1
from productstock a,v_rukutest b
where a.factorycode=b.factorycode and b.productcode=a.productcode
and b.storagecode=a.storagecode and b.batchcode=a.batchcode)
insert into productstock (factorycode,storagecode,productcode,batchcode,stock)
select factorycode,storagecode,productcode,batchcode,basedigit
from v_rukutest
where dcode=@dcode
return
end
------解决方案--------------------
create proc testproductstock2
@dcode varchar(20),
@funcid int,
@model int
as
begin
set nocount on
if @model =1
begin
select * from v_rukutest b
select * from productstock a
update a set
stock = isnull(stock,0)+isnull(b.basedigit,0) FROM productstock AS a,v_rukutest AS b
where a.factorycode=b.factorycode and a.productcode=b.productcode
and a.storagecode=b.storagecode and a.batchcode=b.batchcode
end
if not exists (select 1 from productstock AS a with (nolock),v_rukutest AS b
where a.factorycode=b.factorycode and b.productcode=a.productcode
and b.storagecode=a.storagecode and b.batchcode=a.batchcode)
insert into productstock (factorycode,storagecode,productcode,batchcode,stock)
select factorycode,storagecode,productcode,batchcode,basedigit
from v_rukutest where dcode=@dcode
return
end
------解决方案--------------------
因为原写法中a,b表没有关联关系.
------解决方案--------------------
因为你在语句中引用了表xx的字段,但是没有在语句中写xx表,比如你是这么写的:
select *
from a
where a.id = xx.id
而应该写成:
select *
from a , xx
where a.id = xx.id
你应用了xx表的id字段,所以必须要在from 中写上 xx
------解决方案--------------------
具体要看2个表的关联关系是否正确,是否关联的结果为空集,空集即没有更新喔.