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

  • A few things to notice:

    1) (regarding your question)

    The problem is with @entrydateconv = DATEADD(day,-29,getdate()) .

    Since you "normalized" @entrydateconv, your WHERE condition will only be true exactly at midnight for each day.

    You should change it to

    @entrydateconv = dateadd(dd, datediff(dd,0, GetDate() ),-29)

    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

    3) and finally:

    What is the specific reason to use a cursor?

    I strongly recommend to try to change your cursor into a set-based approach to help performance.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]