"Rudi Groenewald" <tj**@tjoppie.co.za> wrote in message
news:bo**********@ctb-nnrp2.saix.net...
Hi there,
I need to create a stored procedure almost like "Current_user()" to return
to me the total rows in a table.. Is this possible? plz help
Rudi
This is one possible approach:
create proc dbo.GetRows
@table sysname,
@countrows int = 0 OUTPUT
as
set nocount on
begin
declare @sql nvarchar(1000),
@numrows int
set @sql = N'select @numrows = count(*) from ' + @table
exec sp_executesql
@sql,
N'@numrows int OUTPUT',
@numrows OUTPUT
set @countrows = @numrows
end
go
declare @i int
exec dbo.GetRows @table = 'sysobjects', @countrows = @i OUTPUT
select @i
go
Simon