Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Retrieving the count from a derived SQL
Message
From
28/03/2010 21:55:43
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01457748
Message ID:
01457753
Views:
22
>Do you mean
>
>select Temp.NoThread, count(*) over (partition by Temp.NoThread) as CountThreads
> from (SELECT Top 10 NoThread FROM Thread ORDER BY Numero DESC) Temp
This returns 1 for all records.

If you look at the main page, there is a top 10 for the most recent threads. Until tonight, I was doing a main SQL to collect the most recent 10 threads. Then, in the loop, for the HTML table generation, which is a For/Next 10 times, I was doing another SQL to collect the amount of messages in each thread. Tonight, I tried to simplify that by doing it all in the main SQL and avoid doing another SQL for each of those 10 records that I process in the loop. However, I cannot put the COUNT(*) in the inner SQL as this count would only apply on the WHERE clause of that inner SQL and this wouldn't be good as it wouldn't cover the entire table. So, I have to find a way to get the count once I have found the 10 records I need to deal with. And, this can only be done at the external level such as you mentioned in your message. We just need to find the right syntax.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform