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 |
|
desikankannan
Posting Yak Master
152 Posts |
Posted - 2010-02-09 : 01:09:57
|
| Hi,iam new to sql stored procdure and function i wants to get number of rows in table , if there is no row in a table it should fire 0pls guide to write stored procdure or sql functionDesikankannan |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2010-02-09 : 01:15:35
|
| create procedure procedure_nameasbeginSelect COUNT(*) as no_of_rows from table_nameEndSenthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
desikankannan
Posting Yak Master
152 Posts |
Posted - 2010-02-09 : 01:24:34
|
can i pass parametercreate procedure numberofcount(fieldname,tablename), i wants to fire zero if there is no row in the tablepls guide mequote: Originally posted by senthil_nagore create procedure procedure_nameasbeginSelect COUNT(*) as no_of_rows from table_nameEndSenthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/
Desikankannan |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-02-09 : 01:32:55
|
| [code]select sysobjects.name,sysindexes.rowcnt from sysindexes inner join sysobjects on sysobjects.id=sysindexes.idwhere xtype='U' and FirstIAM is not null and sysobjects.name='yourtablename'[/code]PBUH |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-02-09 : 01:33:35
|
you are counting rows in a table, why would you need "fieldname" ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-02-09 : 01:45:37
|
| [code]select sysobjects.name as tablename,sysindexes.rowcnt,Syscolumns.name as columnname from sysindexes inner join sysobjects on sysobjects.id=sysindexes.id inner join Syscolumns on syscolumns.id=sysindexes.idwhere sysobjects.xtype='U' and FirstIAM is not null and sysobjects.name='yourtablename'and Syscolumns.name='yourcolumnname'[/code]PBUH |
 |
|
|
|
|
|