Try this:
USE Northwind;
GO
CREATE FUNCTION ufn_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 = @TableName
and index_id =1
RETURN @rowCnt
END;
GO
SELECT dbo.ufn_f_rec_cnt ('Customers');
GO
-- 91
Reference: http://ift.tt/1eN7Pnt
Kalman Toth Database & OLAP Architect SQL Server 2014 Design & Programming
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012
No comments:
Post a Comment