tags:

views:

37

answers:

2

I am writing my join query by the following way

    UPDATE  UPLOAD_TEMP
    SET     UPLOAD_TEMP.Borr_Add_Req = t2.YesNoResponse,
    FROM    UPLOAD_TEMP t1
    INNER JOIN GB_RequiredFields t2 ON t1.State = t2.StateCode
                                      AND t1.County_Id = t2.CountyId
                                      AND t1.Group_code = t2.Doc_type_group_code

However it can also be written this way as well

    UPDATE  UPLOAD_TEMP
    SET     UPLOAD_TEMP.Borr_Add_Req = t2.YesNoResponse,
    FROM    UPLOAD_TEMP t1
    INNER JOIN GB_RequiredFields t2 ON t1.State = t2.StateCode
    WHERE  t1.County_Id = t2.CountyId
       AND t1.Group_code = t2.Doc_type_group_code

IS there any difference between both and which is the preferred way to code.

A: 

Both queries will have the same result and your sql-server should handle both in the same way. So there is no difference at all - just how you want to do it. You even can do it the following way:

  UPDATE  UPLOAD_TEMP
    SET     UPLOAD_TEMP.Borr_Add_Req = t2.YesNoResponse,

    FROM    UPLOAD_TEMP t1, GB_RequiredFields t2
    WHERE
             t1.State = t2.StateCode
             AND t1.County_Id = t2.CountyId
            AND t1.Group_code = t2.Doc_type_group_code
Pesse
Very old style JOIN. Bad practice.
gbn
I don't like it either, but who says Bad practice? It doesn't matter for the DBMS, it's just for readability and that is mainly affected by how you did it in the past.
Pesse
@Pesse: well, the old style outer join *= =* is deprecated after SQL Server 2008, so you'll have a complete mis.mash of styles
gbn
Oh, I didn't know that it's deprecated. Thanks for the info.
Pesse
+3  A: 

That's an age-old argument - whether to specify additional WHERE arguments in the JOIN clause or as a separate WHERE.

I prefer the approach of defining only those arguments that really make up the JOIN inside the JOIN clause, and everything else later on in the WHERE clause. Seems cleaner to me.

But I think in the end, functionally, it's the same - it's just a matter of personal preference, really.

marc_s