Tuesday, January 9, 2007

db_index

Database Index
--------------

1. Error During Microsoft SQL Server 2005 Setup
2. List last days of months

Error During Microsoft SQL Server 2005 Setup



Error details
---------------
The SQL Server System Configuration Checker cannot be executed due to WMI configuration on the machine XX Error:2147749896 (0x80041008).

Solution
-----------
Open the command line and run the command below:
rundll32.exe setupapi,InstallHinfSection WBEM 132 %windir%\inf\wbemoc.inf

Thursday, January 4, 2007

SQL Script : Lists last days of months

Lists last days of month beginning from given month of year until given year.

DECLARE @last_day_of_month AS SMALLDATETIME,
@first_day_of_next_month AS SMALLDATETIME,
@beginning_month AS NVARCHAR(2),
@beginning_year AS NVARCHAR(4),
@until_year AS NVARCHAR(4),
@days_in_month AS SMALLINT

SET @beginning_year = '2006'
SET @beginning_month = '05'
SET @until_year = '2006'

SET @last_day_of_month = CONVERT(DATETIME,@beginning_month+'/01/'+@beginning_year,101)
SET @first_day_of_next_month = DATEADD(mm,1,@last_day_of_month)

WHILE YEAR(dateadd(DD,30, @last_day_of_month))<=CAST(@until_year AS SMALLINT)
BEGIN
SET @days_in_month = datediff(DD,@last_day_of_month,@first_day_of_next_month)-1
SET @last_day_of_month=dateadd(DD,@days_in_month, @last_day_of_month)
SET @first_day_of_next_month=dateadd(MM, 1, @first_day_of_next_month)
PRINT @last_day_of_month
END


Output
-------------------
May 31 2006 12:00AM
Jun 30 2006 12:00AM
Jul 31 2006 12:00AM
Aug 31 2006 12:00AM
Sep 30 2006 12:00AM
Oct 31 2006 12:00AM
Nov 30 2006 12:00AM
Dec 31 2006 12:00AM