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

Logic Precedence Expand / Collapse
Author
Message
Posted Wednesday, February 12, 2014 8:02 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 11:08 PM
Points: 21,231, Visits: 14,940
david.wright-948385 (2/12/2014)
sknox (2/12/2014)
...This can be alleviated by formatting, e.g:
WHERE
(
(a = b)
OR
(b = c)
)
AND
...

as opposed to
WHERE ((a = b) OR (b = c)) AND ((c = d) OR ((d = e) AND (e = f)))


Exactly. IMHO, this goes for general query layout too.


+10




Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #1540753
Posted Wednesday, February 12, 2014 9:20 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Yesterday @ 7:53 AM
Points: 4,386, Visits: 3,396
Simple... Thanks, Steve!
Post #1540850
Posted Wednesday, February 12, 2014 9:44 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 8:07 AM
Points: 1,765, Visits: 2,139
david.wright-948385 (2/12/2014)
Exactly. IMHO, this goes for general query layout too.


My old boss thought I was being too neat when I put each join criteria on a separate line and each predicate of the where clause on it's own line. Then again, he wrote all his queries in lower case only, no spaces, and used the text editor line length as the only line "terminator". Guess who's code was easier to maintain.


Please don't go. The drones need you. They look up to you.
Connect to me on LinkedIn
Post #1540868
Posted Wednesday, February 12, 2014 11:37 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 7:01 AM
Points: 2,006, Visits: 2,005
To illustrate the points being made about parenthesis.

DECLARE @Logic TABLE ( ID INT, Product VARCHAR(50) );

INSERT INTO @Logic
VALUES ( 1, 'Baseball Hat' ),
( 2, 'Bicycle' ),
( 3, 'Snowboard' ),
( 4, 'Goggles' ),
( 5, 'Shows' );

SELECT ID
FROM @Logic
WHERE (Product = 'Bicycle' OR Product = 'Snowboard') AND ID = 4;

Changes the answer to the QotD.

Enjoy!
Post #1540933
Posted Wednesday, February 12, 2014 12:13 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 7:12 PM
Points: 2,148, Visits: 487
Easiest SSC question in AGES. Thx SJ.
Post #1540941
Posted Wednesday, February 12, 2014 12:38 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Monday, July 7, 2014 9:38 AM
Points: 1,780, Visits: 582
easy one..
Thanks Steve.
Post #1540951
Posted Wednesday, February 12, 2014 6:20 PM


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: 2 days ago @ 10:34 AM
Points: 3,261, Visits: 1,955
Easy one. Surprised only 69% got it right.
Post #1541000
Posted Friday, February 14, 2014 7:21 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 8:38 AM
Points: 1,828, Visits: 1,362
Ed Wagner (2/12/2014)
It was a simple question, but nonetheless a good one. How many times have we all been tripped up somewhere and spent hours on it, only to find that the problem was something so simple that we don't even want to admit it to ourselves? Always good to keep the basics in mind, no matter how far back they get.

+1 Great question Steve. Ed, amen to your post. I must say, it's happened to me before and a good refresher on the basics is always welcome.




Everything is awesome!
Post #1541593
Posted Tuesday, March 11, 2014 2:06 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: Monday, July 21, 2014 6:24 AM
Points: 3,537, Visits: 2,647
Interesting one for me. Thanks Steve.
Post #1549587
« Prev Topic | Next Topic »

Add to briefcase «««123

Permissions Expand / Collapse