Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 123»»»

BETWEEN a hard place and a rock Expand / Collapse
Author
Message
Posted Tuesday, June 11, 2013 10:49 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 3:16 PM
Points: 6,141, Visits: 8,404
Comments posted to this topic are about the item BETWEEN a hard place and a rock


Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #1462448
Posted Tuesday, June 11, 2013 10:55 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, December 2, 2014 9:20 AM
Points: 1,372, Visits: 1,567
Interesting question.....completely missed and gone off-track, feeling like "pressed between the hard place and rock"



~ Lokesh Vij

Guidelines for quicker answers on T-SQL question
Guidelines for answers on Performance questions

Link to my Blog Post --> www.SQLPathy.com

Follow me @Twitter

Post #1462449
Posted Tuesday, June 11, 2013 11:49 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, February 6, 2014 4:15 AM
Points: 1,242, Visits: 1,546
Lokesh Vij (6/11/2013)
Interesting question.....completely missed and gone off-track, feeling like "pressed between the hard place and rock"



+1




Thanks
Vinay Kumar
-----------------------------------------------------------------
Keep Learning - Keep Growing !!!
www.GrowWithSql.com

Post #1462459
Posted Wednesday, June 12, 2013 1:34 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, December 17, 2014 12:30 AM
Points: 1,804, Visits: 783
very "nasty" question missed it all together - lost in translation - between computer screen and my brain :p

Hope this helps...

Ford Fairlane
Rock and Roll Detective





Post #1462486
Posted Wednesday, June 12, 2013 3:23 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 2:31 PM
Points: 3,121, Visits: 3,250
Wonderful!
Regards,
IgorMi




Igor Micev,
SQL Server developer at Seavus
www.seavus.com
Post #1462515
Posted Wednesday, June 12, 2013 5:18 AM
Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Today @ 3:15 PM
Points: 679, Visits: 987
Thanks for the nice question with plenty of knowledge involved, but I've got it just because none of the above made sense for me, and the explanation is not 100% correct as even if we have 5 Null values in the table, the operator EXCEPT will act as explained in BOL:

EXCEPT returns any distinct values from the left query that are not also found on the right query.

So it will never ever return 5 rows, if NULL values come to play, there will be just one row with NULL value in it.

declare @t table (numericColumn int)

insert into @t values (-10)
insert into @t values (-9)
insert into @t values (-8)
insert into @t values (-7)
insert into @t values (-6)
insert into @t values (-5)
insert into @t values (-4)
insert into @t values (-3)
insert into @t values (-2)
insert into @t values (-1)
insert into @t values (0)
insert into @t values (1)
insert into @t values (2)
insert into @t values (3)
insert into @t values (4)
insert into @t values (5)
insert into @t values (6)
insert into @t values (null)
insert into @t values (null)
insert into @t values (null)
insert into @t values (null)
insert into @t values (null)

SELECT *
FROM @t
EXCEPT
SELECT *
FROM @t
WHERE NOT (NumericColumn BETWEEN -1 AND -10);

Cheers
Post #1462560
Posted Wednesday, June 12, 2013 5:26 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 3:16 PM
Points: 6,141, Visits: 8,404
raulggonzalez (6/12/2013)
Thanks for the nice question with plenty of knowledge involved, but I've got it just because none of the above made sense for me, and the explanation is not 100% correct as even if we have 5 Null values in the table, the operator EXCEPT will act as explained in BOL:

EXCEPT returns any distinct values from the left query that are not also found on the right query.

So it will never ever return 5 rows, if NULL values come to play, there will be just one row with NULL value in it.

Good point, and maybe I should have included that in my explanation.
What you forget, though, is that EXCEPT applies the distinct algorithm to the entire result of the SELECT. And I think it's safe to assume that the table has more columns than just the NumericColumn used in the BETWEEN. In your repro, if you add a second column and make sure it has different values in the five rows with a NULL in NumericValue, you'll get 5 rows returned.



Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #1462563
Posted Wednesday, June 12, 2013 5:28 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 3:16 PM
Points: 6,141, Visits: 8,404
Ford Fairlane (6/12/2013)
very "nasty" question missed it all together - lost in translation - between computer screen and my brain :p

Thanks! (Goes for the other replies as welll).

I was aware that this is a nasty question. I deliberately picked a title that at least gives a hint about the most nastiest incorrect answer.



Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #1462564
Posted Wednesday, June 12, 2013 6:06 AM


UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Yesterday @ 1:45 PM
Points: 1,494, Visits: 1,774
More proof that one should not attempt QOTD before the morning dose of caffeine.
Post #1462577
Posted Wednesday, June 12, 2013 6:13 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, February 6, 2014 4:15 AM
Points: 1,242, Visits: 1,546
batgirl (6/12/2013)
More proof that one should not attempt QOTD before the morning dose of caffeine.

Great one




Thanks
Vinay Kumar
-----------------------------------------------------------------
Keep Learning - Keep Growing !!!
www.GrowWithSql.com

Post #1462579
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse