存储过程返回空表

时间:2015-07-08 19:54:34

标签: sql-server-2008 stored-procedures

我正在尝试执行以下执行存储过程的命令:

exec FSDBMR.dbo.usp_zPlannedOrder 16352705, 0.0000, 'Y'

然而,它返回一个空表:

enter image description here
但是,当我通过Web应用程序执行存储过程时,它会返回结果,但不会在我使用SQL Server Management Studio运行时返回。

如何运行存储过程并获得应该返回的结果?存储过程没有任何问题,但以防万一:

USE [FSDBMR]
GO
/****** Object:  StoredProcedure [dbo].[usp_zPlannedOrder]    Script Date: 07/08/2015 15:46:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



ALTER procedure [dbo].[usp_zPlannedOrder]


 @anReportInstanceID      int
,@afmultiplier            float
,@DeleteTempData          varchar(1) = 'Y'                    -- 'Y' means delete the temp data

as

select im.ItemNumber
      ,case 
       when im.MakeBuyCode = 'M' 
       then im.Planner
       else im.Buyer
       end as PlannerBuyer  -- two type, 'C' and 'S'
      ,imd.ReplanCode
      ,im.LastPeriodReviewDate   ReplanDate
      ,im.ItemDescription
      ,im.ItemUM
      ,im.ItemRevision
      ,im.MakeBuyCode
      ,im.ItemType
      ,im.ItemStatus
      ,im.OrderPolicy
      ,im.IsInspectionRequired
      ,im.DecimalPrecision
      ,imd.OnHandQuantity
      ,case
       when rsd.SupplyDemandType = 'D' or rsd.SupplyDemandType = 'S' 
       then convert(char(1),rsd.StartForecastPeriod) 
       else '' 
       end StartForecastPeriod
      ,case 
       when rsd.SupplyDemandType = 'I' 
       then null 
       else rsd.RequiredDate
       end RequiredDate
      ,case 
       when rsd.SupplyDemandType = 'D' 
       then rsd.GrossRequiredFlag
       else null
       end GrossRequiredFlag
      ,case rsd.PlannedOrderQuantity
       when 0
       then case rsd.SupplyDemandType
            when 'D'
            then rsd.GrossRequiredQuantity * @afmultiplier
            else null 
            end
       else null
       end GrossRequiredQuantity
      ,case rsd.PlannedOrderQuantity
       when 0
       then case rsd.SupplyDemandType
            when 'S'
            then rsd.ScheduledReceiptQuantity * @afmultiplier
            else null 
            end
       else null
       end ScheduledReceiptQuantity
      ,rsd.ProjectedAvailableQuantity * @afmultiplier ProjectedAvailableQuantity
      ,case rsd.PlannedOrderQuantity
       when 0 then null
       else rsd.PlannedOrderQuantity * @afmultiplier
       end PlannedOrderQuantity
      ,case 
       when rsd.SupplyDemandType = 'P' 
       then 'P'--'CUSTOM PROD INV'
       else rsd.PeggingInformation
       end PeggingType
      ,rsd.MessageCount Messages
      ,rsd.SupplyDemandKey SuperKey
from FS_Item im (readuncommitted)
join FS_ItemData imd  (readuncommitted) on (im.ItemKey = imd.ItemKey)
left join FSDBMRTemp.dbo.FS_ReportSDASupplyDemand rsd  (readuncommitted) on im.ItemKey = rsd.ItemKey

where rsd.ReportInstanceKey =@anReportInstanceID 

order by ItemNumber, RequiredDate, TopLevelDemandKey, SupplyDemandType desc, rsd.SupplyDemandKey


-- delete Instance from FS_ReportSDASupplyDemand and FS_ReportSDASupplyDemand table
-- the 3rd parameter for usp_ReportDeleteInstance is for SequenceNo,we do not need here
exec usp_ReportDeleteInstance @anReportInstanceID, null , null

return

1 个答案:

答案 0 :(得分:0)

请确保在运行Web版本的同一实例/ sql server数据库上执行存储过程。可能是数据可能存在于一台服务器而非其他服务器上的情况!