如何在SQL Server中应用自定义条件,从表中计算总行数? [英] how to apply custom condition in sql server with count total rows from table?

查看:77
本文介绍了如何在SQL Server中应用自定义条件,从表中计算总行数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的查询来计算表中的总行数并且它正常工作。

i use below query for count total rows from table and it's working.

SELECT [rows] FROM sysindexes
WHERE id = OBJECT_ID('dbo.tableName') AND indid < 2

--instate of 

SELECT COUNT(*) FROM tablename 





现在我必须申请



now i have to apply where condition like

SELECT COUNT(*) FROM tablename  where [EntryDate] between ('10/10/2013') and ('01/01/2014')





现在我必须在我的第一个查询中应用这个条件。怎么样。??



请帮忙。



提前致谢。



now i have to apply this where condition in my first query. HOW.??

Please help.

Thanks in advance.

推荐答案

我认为这是不可能使用第一个查询第二个查询是唯一的选择。原因是sysindex表存储了表中的总行数而未过滤的行。
I think this is not possible using first query second query is the only option. The reason is the sysindex table stores the total number of rows in the table and NOT filtered rows.


这篇关于如何在SQL Server中应用自定义条件,从表中计算总行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆