Reputation: 159
I'm creating a report in Reporting Services, I need a query to return a list of values, a count of each of the individual values, and the results of those values from a table-valued function. Here is my code:
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
This returns the following error: The multi-part identifier "Samples.Value" could not be bound. It's talking about the Samples.Value parameter in the dbo.PDFunction() call
Can anyone help me out? Thank you
Upvotes: 1
Views: 803
Reputation: 247690
Try using a CROSS APPLY to pass in the Samples.value
to your function, this assumes the function is a table-valued function:
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
Upvotes: 2