Monday, April 19, 2010

Get the Row Count

Get the Row Count using procedure, insted of select count (*) table Name

USE [DBName]
GO
/****** Object: StoredProcedure [dbo].[Sp_RowCount] Script Date: 04/19/2010 17:40:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE Proc [dbo].[Sp_RowCount]( @Tname as varchar(100)) As
Declare @SQL Varchar(500)
Set @SQL='Select Object_Name(Id) As [Table Name], Rows From sysindexes Where indid < 2 And Id=' + Str(Object_Id(@Tname)) // the case if u want only count u remove the first colum of (table name).
Exec (@SQL)

Copyright © 2009 Angel