SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Nulls


Nulls

Author
Message
SanDroid
SanDroid
SSCarpal Tunnel
SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)

Group: General Forum Members
Points: 4638 Visits: 1046
Artur Komkov (12/9/2010)
What's why I always try to avoid nullable columns or make something like that:

select * from dbo.Employees where EmployeeID
not in (SELECT isnull(NullableColumn,0) FROM NullOperation)


Artur should get a gold star and extra points for using the function that was created to keep the ANSI NULL issue the question points out from occuring. I work on a database application that has 3000+ stored procedures. Almost all of them use the isnull function.
Hugo Kornelis
Hugo Kornelis
SSC-Dedicated
SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)

Group: General Forum Members
Points: 34414 Visits: 13121
Artur Komkov (12/9/2010)
What's why I always try to avoid nullable columns or make something like that:

select * from dbo.Employees where EmployeeID
not in (SELECT isnull(NullableColumn,0) FROM NullOperation)

While that would indeed avoid this issue, it also makes it a lot harder for the optimizer to use an index (if any) on the NullableColumn. Here is an alternative that will still use indexes:
SELECT   *   -- Use column list instead!
FROM dbo.Employees AS e
WHERE NOT EXISTS
(SELECT *
FROM NullOperation AS n
WHERE n.NullableColumn = e.EmployeeID);




Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
phil.wood 94423
phil.wood 94423
SSC Veteran
SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)

Group: General Forum Members
Points: 203 Visits: 65
The code returns an error:

[color=#FF0000]Msg 3701, Level 11, State 5, Line 1
Cannot drop the table 'dbo.NullOperation', because it does not exist or you do not have permission.[/color]

The table is created using default schema which the contributor has assumed to be dbo (evident in the 'drop table dbo.NullOperation' statement). My default schema is not dbo!

Having said that, I still like the question because it has proven its point - the error occurred AFTER the empty recordset was returned by the select statement.
RichardBo
RichardBo
SSC Eights!
SSC Eights! (852 reputation)SSC Eights! (852 reputation)SSC Eights! (852 reputation)SSC Eights! (852 reputation)SSC Eights! (852 reputation)SSC Eights! (852 reputation)SSC Eights! (852 reputation)SSC Eights! (852 reputation)

Group: General Forum Members
Points: 852 Visits: 251
I have tried to avoid NOT IN clauses, I couldn't remember why but here it is.
I usually use outer joins eg

select * from #Employees e
left outer join #NullOperation n
on e.EmployeeID = n.NullableColumn
where n.NullableColumn IS NULL

so that I get what I expect, which is what we all want!
SanDroid
SanDroid
SSCarpal Tunnel
SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)

Group: General Forum Members
Points: 4638 Visits: 1046
phil.wood 94423 (12/10/2010)

My default schema is not dbo!


Most QOTD readers that actually run or test the QOTD scripts do so in a default NON Production installation of SQL server that is easily rebuilt. Think Virtual PC with a Snapshot, or a server with a good Ghost backup image.

Also a database where you have DBO schema access is prefered and taken for granted, unless otherwise stated in the script or example code.

Good thing the QOTD was not about a script to clear all event and server logs and clean the DMV's of historical data... Cool
Tom Thomson
Tom Thomson
SSC Guru
SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)

Group: General Forum Members
Points: 50760 Visits: 13159
Good question with clear answer options, but as several have pointed out the explanation is not a real explanation.

Tom

phil.wood 94423
phil.wood 94423
SSC Veteran
SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)

Group: General Forum Members
Points: 203 Visits: 65
SanDroid (12/10/2010)
phil.wood 94423 (12/10/2010)

My default schema is not dbo!


Most QOTD readers that actually run or test the QOTD scripts do so in a default NON Production installation of SQL server that is easily rebuilt. Think Virtual PC with a Snapshot, or a server with a good Ghost backup image.

Also a database where you have DBO schema access is prefered and taken for granted, unless otherwise stated in the script or example code.

Good thing the QOTD was not about a script to clear all event and server logs and clean the DMV's of historical data... Cool


Isn't it normal to have development environments, virtual or otherwise, set up as similarly as possible to production? It should be.
SQLRNNR
SQLRNNR
SSC Guru
SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)

Group: General Forum Members
Points: 144687 Visits: 18651
Thanks for the question.

Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw
Learn Extended Events

SanDroid
SanDroid
SSCarpal Tunnel
SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)

Group: General Forum Members
Points: 4638 Visits: 1046
phil.wood 94423 (12/13/2010)
SanDroid (12/10/2010)
phil.wood 94423 (12/10/2010)

My default schema is not dbo!


Most QOTD readers that actually run or test the QOTD scripts do so in a default NON Production installation of SQL server that is easily rebuilt. Think Virtual PC with a Snapshot, or a server with a good Ghost backup image.

Also a database where you have DBO schema access is prefered and taken for granted, unless otherwise stated in the script or example code.

Good thing the QOTD was not about a script to clear all event and server logs and clean the DMV's of historical data... Cool


Isn't it normal to have development environments, virtual or otherwise, set up as similarly as possible to production? It should be.


My point is don't blame the author just becuase you do not understand how his script will run in your custom environment.

Of course your Dev environment should match your prod.
But I would not run any QOTD code, or any code from the internet, in a database supporting Development of a specific application either.
mtillman-921105
mtillman-921105
Hall of Fame
Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)

Group: General Forum Members
Points: 3240 Visits: 3854
Good question - thanks! NULLs can be hazardous, they should come with a warning.

______________________________________________________________________
The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge. - Stephen Hawking
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search