|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Monday, November 21, 2011 12:49 PM
Points: 3,
Visits: 7
|
|
Interesting article. I'm glad I always use the newer syntax. To the poster who said the problem was that the problem was not knowing which part of the where to apply, I would have to disagree. It is something more than that, although I don't know what. For example, I tried the following: SELECT testnull = CASE WHEN tmp.Rats_filename IS NULL THEN 'NULL ' WHEN tmp.Rats_filename IS NOT NULL THEN 'NOT NULL' ELSE 'OTHER' END , * FROM (SELECT * FROM UUG_APP_DVLP.dbo.[IIAFeedTransaction] s , UUG_APP_DVLP.dbo.[RATSIIAFeedTransaction] o WHERE S.IIATransactionId *= substring(rats_filename,1+ patindex ('%{________-____-____-____- ____________}%',rats_filename),36) )TMP WHERE tmp.Rats_filename IS NOT NULL ORDER BY 2 For the above, there should be no problem with what to join together. The second WHERE should work properly, and I would expect it to work the same as the CASE statement. But it doesn't!!!. See results below: Testnull | IIATransactionId | | RATS_FILENAME | DATE_ENTERED | NULL | 9B33A776-408B-4928-AE2A-0FF43995DE12 | 1 | NULL | NULL | NULL | 8EEA51CE-D87A-4F76-B9C1-7AD11532D444 | 0 | NULL | NULL | NULL | 5D31FD56-7C0B-408B-83A5-864B7BD35ADC | 1 | NULL | NULL | NOT NULL | 365A0FD8-5042-4297-A082-8F5B11450AF4 | 1 | CISF-{260021}-{365A0FD8-5042-4297-A082-8F5B11450AF4}-{7A050246-59F3-4E72-BFD2-40EB183B7D3C} | 2006-05-03 13:46:21.470 | NOT NULL | 16706611-C94D-4FBC-8F4E-9077C3B9E697 | 1 | CISF-{260346}-{16706611-C94D-4FBC-8F4E-9077C3B9E697}-{73916523-EC71-4989-BE99-1EDB507D67DF} | 2006-05-03 13:46:21.470 | NOT NULL | 55DD6703-9693-45E2-A339-987066EA2864 | 2 | RA-1-{259590}-{55DD6703-9693-45E2-A339-987066EA2864}-{EF41CFCE-20BA-4D2D-A4C8-121BFC7DAEE3} | 2006-05-03 13:46:21.470 | NULL | A721BD38-9C76-4C3A-A7C5-9CC0227F90F4 | 0 | NULL | NULL | NOT NULL | F4849137-6454-46E5-9811-A6985A189249 | 1 | RA-2-{219960}-{F4849137-6454-46E5-9811-A6985A189249}-{F7267BD6-62CB-4379-8533-C413DD5EA402} | 2006-05-03 13:46:21.470 |
Moral of this story is: Stay with the new syntax.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Yesterday @ 1:39 PM
Points: 2,818,
Visits: 1,038
|
|
You might think "there should be no problem with what to join together" because you put parentheses around the derived table, but the query optimizer has its own agenda sometimes. What did the execution plan look like? You have got to give the query compiler credit, it's not easy to fool it with an extra level of parenthesis. A working hypothesis might be that in SQL Server once you use an old=style join then all WHERE clauses that refer to tables A or B (either singly or together) are interpreted as join conditions. I don't know this to be true, but it explains the examples you've presented. The difference in Oracle may be that it only uses conditions on both tables for joining, while conditions on only one table are used for filtering.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, May 16, 2006 4:37 AM
Points: 1,
Visits: 1
|
|
SELECT * FROM ( SELECT 'Naughty Optimizer; Real developers use parenthesis to clarify default behavior AND SPECIFY REQUIRED BEHAVIOR.' AS 'My two cents', 'Using SELECT ColTitle = Expr is nice for swapping UPDATE for SELECT when Expr is a col name in UPDATE target, but this is legacy syntax' AS 'Farewell Old Friend' WHERE 1 = 1   AS Moral_of_Story__Use_The_New_Syntax
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Sunday, September 16, 2012 3:26 AM
Points: 1,038,
Visits: 443
|
|
I've always used the newer syntax as it made things obvious and clear to me... I suppose if I had grown up using the old syntax I might think differently - but I also shudder to think of the difficulties I would've found trying to express what I needed in a query using the old syntax when the new syntax is just so easy and straightforward to both write, debug and explain to others. Yay for new syntax - or, as far as I was concerned, the only syntax anyway 
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Yesterday @ 4:45 AM
Points: 1,559,
Visits: 656
|
|
As with most things, it's a matter of habit. Things we know are 'easy', things we don't know are 'difficult'. There's no rocketscience about that.  I started out writing T-SQL the old way, and switched to ANSI style sometime around y2k. At that time ANSI was hard, difficult, weird, strange, awkward... take your pick. Of course that was because in the beginning it was something that I didn't knew too well. But with practice comes perfect, and once you get used to it there are no regrets. ANSI is way more clear, concise and easy to write and moreover, to read. There's no doubt when you read a query what the author intended with it when it was written (assuming it was written correctly ofc) The major point is that there's no ambiguity for outer joins - a quite tricky area to 'get right'. I should add as a final note a plug for aliasing. Always alias everything. ANSI outer joins with aliases on all columns and tables is pretty much self-documenting code.  /Kenneth
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Yesterday @ 3:04 PM
Points: 13,375,
Visits: 25,159
|
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Yesterday @ 3:04 PM
Points: 13,375,
Visits: 25,159
|
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Yesterday @ 3:04 PM
Points: 13,375,
Visits: 25,159
|
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Wednesday, May 23, 2007 7:06 AM
Points: 1,
Visits: 1
|
|
Hi,
I had the same issue couple of days back and I solved it by same way (removing and clause and putting where clause).
VS
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Tuesday, June 05, 2012 12:03 PM
Points: 117,
Visits: 163
|
|
There was a post that hit the nail on the head. Your where clause that stipulates that RAT_FILENAME IS NOT NULL does not limit results due to there being no NULL RAT_FILENAME columns... You want to look for NULLs after the join is complete.
More to the point would be something like; /* return all IIAFeedTransaction.IIATransactionId values that are * not used in the RATSIIAFeedTransaction.RAT_FILENAME values */ SELECT IIATransactionId FROM dbo.IIAFeedTransaction WHERE IIATransactionId IN ( SELECT SubString(RATS_FILENAME,1+PatIndex('%{________-____-____-____-____________}%',RATS_FILENAME),36) FROM dbo.RATSIIAFeedTransaction )
|
|
|
|