Home Forums SQL Server 2005 T-SQL (SS2K5) Select statment problem in cursor using datetimes RE: Select statment problem in cursor using datetimes

  • rons-605185 (11/20/2009)


    Per your post below, what is the advantage doing the inner joins versus the code I wrote? I have been only doing T-SQL for a short time and appreciate any tips. Can you explain the differences and pros/cons between the 2 coding methods shown below?

    2) question in general

    You should change your syntax when joining tables.

    Instead of

    FROM dbo.NOTE_tblNote n, dbo.ICOMP_tblEmployee i, XCOMP_tblCompany x, CON_tblContact c

    WHERE

    n.employeeid = i.employeeid

    and n.companyid = x.companyid

    and n.contactid = c.contactid

    I'd recommend

    FROM dbo.NOTE_tblNote n

    INNER JOIN dbo.ICOMP_tblEmployee i ON n.employeeid = i.employeeid

    INNER JOIN XCOMP_tblCompany x ON n.companyid = x.companyid

    INNER JOIN CON_tblContact c ON n.contactid = c.contactid

    Putting your join criteria in the FROM CLAUSE is the ANSI STANDARD and is required in SQL Server 2005 and later when using outer joins.

    Also, it makes your code cleaner when you separate the join criteria between tables (FROM CLAUSE) and the query filter criteria (WHERE CLAUSE).