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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 sql stored procedure to find number of rows

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 0

pls guide to write stored procdure or sql function

Desikankannan

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-02-09 : 01:15:35
create procedure procedure_name
as
begin

Select COUNT(*) as no_of_rows from table_name

End

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

desikankannan
Posting Yak Master

152 Posts

Posted - 2010-02-09 : 01:24:34
can i pass parameter
create procedure numberofcount(fieldname,tablename), i wants
to fire zero if there is no row in the table

pls guide me





quote:
Originally posted by senthil_nagore

create procedure procedure_name
as
begin

Select COUNT(*) as no_of_rows from table_name

End

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/




Desikankannan
Go to Top of Page

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.id
where xtype='U' and FirstIAM is not null and sysobjects.name='yourtablename'

[/code]



PBUH
Go to Top of Page

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]

Go to Top of Page

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.id
where sysobjects.xtype='U' and FirstIAM is not null and sysobjects.name='yourtablename'
and Syscolumns.name='yourcolumnname'
[/code]

PBUH
Go to Top of Page
   

- Advertisement -