Posts

Showing posts from March, 2014

Get All the dates of a specific month

 DECLARE @dataforDate DATETIME, @month int  SET @dataforDate=GETDATE()  SET @month=DATEPART(MONTH,GETDATE())  DECLARE @t TABLE ( days DATETIME )  -- SET NOCOUNT ON added to prevent extra result sets from  -- interfering with SELECT statements.         SET NOCOUNT ON;         WITH    CTE_Days                   AS ( SELECT   DATEADD(month, @month,                                         DATEADD(month, -MONTH(@dataforDate),                                                 DATEADD(day,                                           ...

All Tables records count of a specific database

SELECT @@ServerName AS ServerName,DB_Name(DB_id()) AS DatabaseName,sc.name +'.'+ ta.name TableName,SUM(pa.rows) #OfRows FROM sys.tables ta INNER JOIN sys.partitions pa ON pa.OBJECT_ID = ta.OBJECT_ID INNER JOIN sys.schemas sc ON ta.schema_id = sc.schema_id WHERE ta.is_ms_shipped = 0 AND pa.index_id IN (1,0) GROUP BY sc.name,ta.name ORDER BY SUM(pa.rows) DESC