This should be simple Im just not getting the desired result, i’ve tries this a couple of ways and still not getting anywhere I need to get the total cound of records of the subquery I know this is totally wrong but when but when I put the count on the subquery it still gives me 1 here’s my code:
SELECT COUNT(*) [COUNT]
(
SELECT WP_BlogEntries.BlogEntryID, sys_Objects_Tags.TagID
FROM WP_BlogEntries INNER JOIN sys_Objects_Tags ON
WP_BlogEntries.BlogEntryID = sys_Objects_Tags.SystemObjectRecordID
WHERE WP_BlogEntries.ReleaseDate < GETDATE()
AND WP_BlogEntries.ExpireDate > GETDATE()
AND WP_BlogEntries.Approved = 1
AND WP_BlogEntries.Listed = 1
AND WP_BlogEntries.BlogID = @BlogID
AND TagID = @TagID
GROUP BY WP_BlogEntries.BlogID, BlogEntryID, sys_Objects_Tags.TagID
)
You simply need to alias the subquery and put it into the FROM clause making it into a derived table. Although, if all you want is the count, you don’t need anything in the Select clause (i.e., you could use
Select 1in the subquery’s Select clause and it’d still work.