Sunday, November 20, 2016

Is it possible to compare NULL value to NULL?

Quation:

SELECT  Case When NULL=NULL Then 1
                 ELSE 0 END as result

ANS: 0

my observation:

NULL means just nothing and NULL is not equal to zero or some other value or empty string. If you need to attach a specific meaning to NULL then missing or absent data. Nothing cannot be the same as nothing. Nothing cannot be compared to nothing. Because case condition fails then it will return 0.

Why it will be 0 ,if you have any ideas let me know 

Thursday, November 17, 2016

EOMONTH() New Date Function In 2012

it is the new date time function in sql server 2012 and and higher versions.It cannot be remoted to servers with a version lower than SQL Server 2012.
Definition:
    Returns the last day of the month that contains the specified date, with an optional offset.
syntax :
  EOMONTH ( start_date [, month_to_add ] )  
Examples:
DECLARE @date DATETIME = '12/1/2011';
SELECT EOMONTH ( @date ) AS Result;
GO
    Result :   2011-12-31  
DECLARE @date VARCHAR(255) = '12/1/2011';
SELECT EOMONTH ( @date ) AS Result;
GO
    Result : 2011-12-31 
DECLARE @date DATETIME ='2011-12-01';
SELECT EOMONTH ( @date ) AS 'This Month';
SELECT EOMONTH ( @date, 1 ) AS 'Next Month';
SELECT EOMONTH ( @date, -1 ) AS 'Last Month';
GO
result
-----------------------
2011-12-31
(1 row(s) affected)
Next Month
-----------------------
2012-01-31
(1 row(s) affected)
2011-11-30
Last Month
-----------------------
(1 row(s) affected)
--> By using EOMONTH function to easyly get perticuar month last date.
                                                                          థాంక్స్ ,
                                                                          బాబ్జి రెడ్డి జి వి