Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
asilter
Starting Member
5 Posts |
Posted - 2007-09-28 : 17:06:55
|
i want to have a user defined function or stored procedure(i don't know which one should be used, anyway!) which returns false if the table has no records, with the table name comes with a parameter.could you give a little code sample?thanx |
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-09-28 : 17:26:26
|
you mean count(*) of table = 0 ?Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
asilter
Starting Member
5 Posts |
Posted - 2007-09-28 : 19:00:43
|
yes please. |
 |
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-09-28 : 19:06:55
|
IF tablename is dynamic you might have to use dynamic sql. Check out sp_ExecuteSQL in books on line. they have some sample code too.Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2007-09-28 : 19:46:24
|
Does the count have to be 100% accurate? If not then something like this could do the trick:SELECT [TableName] = so.name, [RowCount] = MAX(si.rows) FROM sysobjects so, sysindexes si WHERE so.xtype = 'U' AND si.id = OBJECT_ID(so.name) GROUP BY so.name ORDER BY 2 DESC --Lumbago"Real programmers don't document, if it was hard to write it should be hard to understand" |
 |
|
|
|
|