Monday, July 28, 2014

Function Error



When I call this function from a select statement
select f_rec_cnt(table_name) from <AnyTable> -- it is always returning null and no rowcount as the table contains data init
NULL
The AnyTable contains table_name column with value as actual table name in the database, I want the
function to return the number of records in that table.


ALTER FUNCTION Collect.f_rec_cnt ( @TableName VARCHAR(100))
RETURNS INT
AS
BEGIN
DECLARE @rowCnt INT
DECLARE @TableNm varchar(100)
SET @TableNm=''@TableName+''
SELECT @rowCnt = ROWS FROM sys.partitions p
inner join sys.tables t
ON p.object_id = t.object_id
WHERE t.name = @TableNm
and index_id =1
RETURN @rowCnt
END





Neil


No comments:

Post a Comment