tsql - I cant figure out what this SQL query is -


declare @loginid nvarchar(50) set @loginid = null  select * loginusers loginid = @loginid or @loginid  null 

if execute statement rows dont understand how condition processed here.

if @loginid null clause doesn't apply or what?

let me add 2 cents here. try explain code line line. tsql processed in procedural way.

you have:

1- declare @loginid nvarchar(50) 2- set @loginid = null 3-  4- select *  5-   loginusers  6-  loginid = @loginid  7-     or @loginid  null 
  1. the first line (1) defined variable @loginid , type
  2. the second line (remember one, important) assigned value null variable @loginid

then in query, matters where clause , use loginid = @loginid or @loginid null asking here is:

is table field loginid equals defined variable @loginid or equals null

here must remember logic table or

a | b | result (a or b) 0   0         0 1   0         1  0   1         1 1   1         1 

so, remember when said assigned value important? here it, database field loginid not have null values , variable (if there code in between assigning , query) null, therefore in logic table 0 or 1 = true condition true rows in table.

hope understand better.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -