count() in sql 2005

Posted by Kannan1986 under Sql Server on 2/19/2010 | Views : 3263 | Status : [Member] | Replies : 6
Hi,

display total no of recors more then 5 using count() in sql 2005




Responses

Posted by: Vuyiswamb on: 2/19/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Please give us more info on what you want to do.



Thank you for posting at Dotnetfunda
[Administrator]

Kannan1986, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Abhi2434 on: 2/19/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
It doesnt make sense.

Select COUNT(ID) FROM TABLE 
will return you the total no of records in the table.

What do you mean
"more than 5"

I am confused.

www.abhisheksur.com

Kannan1986, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pandians on: 2/21/2010 [Member] [MVP] Silver

Up
0
Down
Hi

Try this...
CREATE TABLE #Table1

(TableName VARCHAR(100), Records INT)

INSERT #Table1
EXEC('SP_MsForEachTable "SELECT ''?'' TableName,COUNT(1) Records FROM ? HAVING COUNT(1) > 5"')

SELECT TableName,Records FROM #Table1

DROP TABLE #Table1

Cheers


Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Kannan1986, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Abhi2434 on: 2/22/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
It is not actually a good idea to create a temporary table for such a small thing.

I think it could be reduced using CASE and joins.

www.abhisheksur.com

Kannan1986, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: perfectchourasia-9163 on: 6/8/2012 [Member] Starter | Points: 25

Up
0
Down
select Count(Address1) from dbo.UserDetail

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

Kannan1986, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: CGN007 on: 6/11/2012 [Member] Silver | Points: 25

Up
0
Down
@Abhi2434
You are right.,Nice explanation as well...

Kannan1986, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response