日期:2014-05-16  浏览次数:20667 次

无法绑定由多个部分组成的标识符
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 (