1

我正在 Reporting Services 中创建一个报表,我需要一个查询来返回一个值列表、每个单独值的计数以及来自表值函数的这些值的结果。这是我的代码:

SELECT        Samples.Value, COUNT(Samples.Value) AS count, pdf.within, pdf.overall
FROM            Samples,dbo.PDFunction(Samples.Value,@Mean,@StDevOverall,@StDevWithin) as pdf
WHERE        (Samples.SampledAt >= @StartDate) AND (Samples.SampledAt <= @EndDate) AND (Samples.ProductId = @ProductID) AND (Samples.TestId = @TestID) AND 
                         (Samples.SetEnum > 0) AND (Samples.Value IS NOT NULL)
GROUP BY Samples.Value

这将返回以下错误:无法绑定多部分标识符“Samples.Value”。它正在谈论 dbo.PDFunction() 调用中的 Samples.Value 参数

谁能帮我吗?谢谢

4

1 回答 1

2

尝试使用 CROSS APPLY 将 传递Samples.value给您的函数,这假定该函数是一个表值函数:

SELECT Samples.Value, 
  COUNT(Samples.Value) AS count, 
  pdf.within, 
  pdf.overall
FROM Samples
CROSS APPLY dbo.PDFunction(Samples.Value,@Mean,@StDevOverall,@StDevWithin) as pdf
WHERE (Samples.SampledAt >= @StartDate) 
  AND (Samples.SampledAt <= @EndDate) 
  AND (Samples.ProductId = @ProductID) 
  AND (Samples.TestId = @TestID) 
  AND (Samples.SetEnum > 0) 
  AND (Samples.Value IS NOT NULL)
GROUP BY Samples.Value, pdf.within, pdf.overall
于 2013-05-29T18:36:03.583 回答