Does anyone know if I can do the following:
I am writing a Stored Procedure that needs to count the next "X" records in a temp table. I have tried the TOP keyword, and it works fine when it is a hard coded value. The problem is that the number of records that I am trying to count will change as we go, and it doesn't let me use the table field there.
Here is a sample:
SELECT COUNT(*)
FROM
(SELECT TOP 5 SiteNo, Treatment
FROM #EligibleAllocations
WHERE SiteNo = Site.SiteNo)
This is part of a larger statement and I need to change the 5 for a field from the larger statement. Any help pointing me in the right direction would be greatly appreciated. ~Brian
I am writing a Stored Procedure that needs to count the next "X" records in a temp table. I have tried the TOP keyword, and it works fine when it is a hard coded value. The problem is that the number of records that I am trying to count will change as we go, and it doesn't let me use the table field there.
Here is a sample:
SELECT COUNT(*)
FROM
(SELECT TOP 5 SiteNo, Treatment
FROM #EligibleAllocations
WHERE SiteNo = Site.SiteNo)
This is part of a larger statement and I need to change the 5 for a field from the larger statement. Any help pointing me in the right direction would be greatly appreciated. ~Brian