October 21, 2015 at 9:33 pm
Comments posted to this topic are about the item The TOP 10 Count
October 21, 2015 at 11:03 pm
Good question, had to pause for thought and do a bit of math!
...
October 22, 2015 at 12:23 am
Good question. Thanks for sharing.
October 22, 2015 at 12:38 am
This was removed by the editor as SPAM
October 22, 2015 at 2:24 am
Of course, if you have more than 2^21 columns in your database, it will return an error ... 😀
October 22, 2015 at 4:41 am
My first thought - 1 row and why the hell there's no such answer, and then
slow down, review carefully all available. 😎
Thanks Eirikur
October 22, 2015 at 4:55 am
This was removed by the editor as SPAM
October 22, 2015 at 4:58 am
Very nice question Eirikur. It makes you stop and think...just for a moment.
October 22, 2015 at 6:41 am
Was looking for the trick.
October 22, 2015 at 6:45 am
Got it right, but only because I read the question too quickly and was looking for "1" as a possible answer, b/c I thought the question read "How many rows are returned?" When "1" wasn't in the list of possible answers, I figured I needed to actually read the question you wrote (vs. the one I thought you wrote)! 😀
If anyone was thinking "1000" for an answer, this will do that, b/c it first returns 10 from the CTE using TOP:
;WITH cte As
(
SELECT TOP (10) *
FROM sys.all_columns
)
SELECT COUNT_BIG(*)
FROM
cte cte1 CROSS JOIN
cte cte2 CROSS JOIN
cte cte3;
Rich
October 22, 2015 at 9:17 am
Very useful question Eirikur, thank you. 🙂 There is also interesting that COUNT_BIG(*) is here a deterministic function,
because the TOP is not specified with an aggregate clause.
See eg.: https://msdn.microsoft.com/en-us/library/ms190317.aspx"> https://msdn.microsoft.com/en-us/library/ms190317.aspx
October 22, 2015 at 10:12 am
Stewart "Arturius" Campbell (10/22/2015)
martin.whitton (10/22/2015)
Of course, if you have more than 2^21 columns in your database, it will return an error ... 😀if one has that many columns, they will have even more serious problems....:hehe:
+1
Don Simpson
October 22, 2015 at 10:14 am
Stewart "Arturius" Campbell (10/22/2015)
martin.whitton (10/22/2015)
Of course, if you have more than 2^21 columns in your database, it will return an error ... 😀if one has that many columns, they will have even more serious problems....:hehe:
It would take 67492 tables with 30000 sparse columns each to reach the limit of a bigint (2^63) - 1;-)
😎
October 22, 2015 at 11:32 am
Two points to Michal L., and take away two from me for not considering which choice actually represented the "1" answer I was seeking :).
October 22, 2015 at 11:38 am
As a thought you could have explained why use Count_Big rather than just Count and included a link.
But there again you could have used Count, and included another option; an error is returned, Possibly?
...
Viewing 15 posts - 1 through 15 (of 19 total)
You must be logged in to reply to this topic. Login to reply