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 2000 Forums
 SQL Server Development (2000)
 tell me how to get no of records in a table !!!

Author  Topic 

senthilramtrs
Starting Member

29 Posts

Posted - 2008-05-15 : 04:11:44
tell me how to get no of records in a table whose table name is given as input to the stored procedure....

i have set a @NOR as output

create procedure retrieve_no_rows @tablename varchar(20), @NOR int output

as

DECLARE @sSQL VARCHAR(200)
SET @sSQL = 'select count(*) from ' + @tablename

Set @NOR = EXEC @sSQL // error on this line

go



Regards,
Senthil Ram TRS

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-15 : 04:16:56
This has been asked a few times last month.
Please search SQLTeam for answer.

Relevant keywords are:

DYNAMIC SQL, sp_executesql, totalt number of records in table



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

senthilramtrs
Starting Member

29 Posts

Posted - 2008-05-15 : 04:43:44
quote:
Originally posted by Peso

This has been asked a few times last month.
Please search SQLTeam for answer.

Relevant keywords are:

DYNAMIC SQL, sp_executesql, totalt number of records in table



E 12°55'05.25"
N 56°04'39.16"







can u make changes in my code
or tell me sme new idea/code pls

Regards,
Senthil Ram TRS
Go to Top of Page

manishm2278
Starting Member

1 Post

Posted - 2008-05-15 : 08:08:42
declare @tablename varchar(100)
DECLARE @sSQL nVARCHAR(200)
set @tablename = 'tblServiceAccts'
SET @sSQL = 'select count(*) NOR from ' + '' + @tablename + ''
exec sp_executesql @sSQL
Go to Top of Page
   

- Advertisement -