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


Nulls


Nulls

Author
Message
SanDroid
SanDroid
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2410 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
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18767 Visits: 12426
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 MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
phil.wood 94423
phil.wood 94423
SSC-Enthusiastic
SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)

Group: General Forum Members
Points: 121 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
Mr or Mrs. 500
Mr or Mrs. 500 (516 reputation)Mr or Mrs. 500 (516 reputation)Mr or Mrs. 500 (516 reputation)Mr or Mrs. 500 (516 reputation)Mr or Mrs. 500 (516 reputation)Mr or Mrs. 500 (516 reputation)Mr or Mrs. 500 (516 reputation)Mr or Mrs. 500 (516 reputation)

Group: General Forum Members
Points: 516 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
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2410 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
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25903 Visits: 12494
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-Enthusiastic
SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)

Group: General Forum Members
Points: 121 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 (66K reputation)SSC Guru (66K reputation)SSC Guru (66K reputation)SSC Guru (66K reputation)SSC Guru (66K reputation)SSC Guru (66K reputation)SSC Guru (66K reputation)SSC Guru (66K reputation)

Group: General Forum Members
Points: 66351 Visits: 18570
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

SanDroid
SanDroid
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2410 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
SSCommitted
SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)

Group: General Forum Members
Points: 1516 Visits: 3852
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