Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2015
    Posts
    6

    Unanswered: Issues with syntax and performance.

    Hello,

    I have got T-SQL query here and would like to know is there any issues with the following TSQL statement in terms of syntax and performance. I really appreciate help here. Thanks.

    SELECT
    *
    FROM
    TableA NOLOCK
    LEFT JOIN TableB ON TableA.ID = TableB.ID
    WHERE
    TableB.Week = 2
    AND dbo.fn_GetTime(TableA.TimeCode) = '14:00'
    GROUP BY
    TableB.DAY
    ORDER BY
    Week

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    #1 don't use "SELECT *". List out the exact columns you want.
    #2 Your scalar function call (fn_GetTime) is not going to be quick. What is the contents of the function?
    #3 Your WHERE clause is turning your LEFT join in to an INNER join. I don't know if that's the behaviour you want or not.
    George
    Home | Blog

  3. #3
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    Provided Answers: 5
    Thank you George! I hadn't seen anyone other than me mention #3 on any board or forum in the past. Which is really surprising as it seems to be a very frequent problem with developers that I have seen. Robert Catterall does make mention of it in his blog post on OUTER JOINS some years back.

    @luka -- See what George said above!
    Dave

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •