Pages

Social Icons

Thursday 22 December 2011

Difference between != NULL and IS NOT NULL


When you deal with NULL in SQL Server you basically work with 3-value logic with all the implications.

IF(@myVar != null)  vs  IF(@myVar is not null)

It basically boils down to the question

what is the difference between: @myVar = null vs @myVar is null

@myVar = null will always evaluate to null as what you are asking is: is the value in @myVar equal to UNKNOWN

As you do not know what the UNKNOWN is this question cannot by answered yes, or no so it evaluates to UNKNOWN

e.g.
    "is 1 = UNKNOWN" - I do not know
    "is 'a' = UNKNOWN" - I do not know
    "is UNKNOWN = UNKNOWN" - I do not know

The last one may be a bit tricky but just imagine that you have 2 boxes with candy and you do not know neither how many candy are in box1 one nor in box2 so asking.
so the answer is I do not know

the second one @myVar is null is different as it is like asking is the value in @myVar UNKNOWN

so the difference is that you specifically ask "is it true that the value stored in the variable is UNKNOWN?", so
    "is 1 UNKNOWN" - NO
    "is 'a' UNKNOWN" - NO
    "is UNKNOWN UNKNOWN" - YES

THX,
RS

Tuesday 13 December 2011

Notepad in C#


Hi,
I have developed a small notepad in C# windows application. In this sample notepad i have given New, Open, Save, Save As, Cut, Copy, Paste, Undo,  Select All, Find, Word-wrap, Font and Color functionality.


Here I am attaching a zip file of the source code. Download Here


Thx,
RS

Thursday 1 December 2011

Call jquery funtion when it is exist.


Some times we need to call a function after chceking that it is exist there or not. This is very simple in jquery. Use that function name in if and if is exist then it will go in if block.


Example : 
function temp(){
  // Sample Code
}

if(temp){
  temp();
}


Like this temp function execute only when it is awailable.

Update XML Node value in SQL-Server 2008


Sometimes we need to change the value of a node in Sql-Server. Here is the example by which we can update the xml node value


Example : 



DECLARE @StrXml AS XML = '<BooksHome><Books>1</Books><Books>2</Books><Books>3</Books><Books>4</Books><Books>5</Books><Books>6</Books></BooksHome>'


DECLARE @i INT = 1
DECLARE @j INT = 141


SET @StrXml.modify('replace value of (//BooksHome/Books[sql:variable("@i")]/text())[1] with sql:variable("@j")')


we can see the updated result as :


SELECT @StrXml