存储过程返回的结果与sql server中的查询不同

时间:2015-03-05 17:48:04

标签: sql-server stored-procedures

我有一个存储过程,其代码类似于此,

if Exists(select * from sysobjects where name = 'tblProducts_Details' and xtype = 'U')
begin
  Drop table tblProducts_Details
End

select * into tblProducts_Details from tblProducts

alter table tblProducts_Details add gcode varchar(50)

update a set a.gcode = b.gcode from tblProducts_Details a
inner join GroupID_GCode_Mapping b
on a.Company = b.Company

alter table tblProducts_Details add group_code int

update a set a.group_code = b.local_group_code from tblProducts_Details a  
inner join Cache.dbo.Z_MAP_GroupID_CGCode_Mapping b
on a.gcode = b.gcode

alter table tblProducts_Details add groupname varchar(2000)

update a set a.groupname = g.name from tblProducts_Details a 
inner join tblProductsGroup g
on a.group_code = g.group_id

当我单独执行上述查询时,它会返回完美的结果。但是当我执行这个存储过程时,有时会返回不同的结果集(某些行的值与所需的值不同)。

我不知道为什么。

1 个答案:

答案 0 :(得分:0)

基础表(GroupID_GCode_Mapping,tblProductsGroup和Cache.dbo.Z_MAP_GroupID_CGCode_Mapping)必须在执行存储过程和检查结果之间进行更改。在proc中包装整个东西没有什么不同。基于'缓存的更新'数据库可能需要很长时间,当你意识到proc已经完成时,数据已经改变了。

相关问题