Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Query Not Working
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01406608
Message ID:
01406615
Views:
40
One more time an explanation by George Mastros on this problem:
----------------------------------------------------------------------------------------------------------------------------
This happens because the 2nd version will not return rows where the data is null.

Declare @Temp Table(Data Int)


Insert Into @Temp Values(NULL)

Insert Into @Temp Values(1)

Insert Into @Temp Values(2)

 

Declare @Search Int

 

Set @Search = NULL

 

Select * From @Temp Where (@Search Is NULL Or Data = @Search)

 

Select * From @Temp Where Data = IsNull(@Search, Data)




The second query will return 2 rows instead of 3.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform