I was wondering if it is possible to use a bound joined table in a CASE statment when declaring a column in a select statment. I have included a simplified example of my problem in the snippet below.Any ideas? Thanks!
SELECT M.MID
,[Count] = CASE (SELECT COUNT(*) FROM Refund R2
WHERE R2.RefundID = R.RefundID) = 1
THEN 'One'
ELSE 'Many'
END
FROM #temp T
JOIN Refund R ON R.RefundID = T.RefundID
The “WHERE R2.RefundID = R.RefundID says that the “R.RefundID cannot be bound.
If you are using SQL Server 2005 or later, you could try a different approach: