SQL Server Development

  • Hi

    I have a query wrt comparing two datetime values.

    i have a query:

    Select Count(1) Records From tblA

    Where Convert(Varchar(10),Row_Insert_Date,103) <= Convert(Varchar(10),GetDate(),103)

    I have few doubts regarding this:

    1. Should we / Should'nt we use Convert. Explanation will be greatly appreciated.

    2. What is the best way to compare dates.

    Thanks

    Azeem.

  • I had a similair question some time ago - http://www.sqlservercentral.com/Forums/Topic731245-338-1.aspx

    BrainDonor

  • Thank you. I went through the thread and found it very useful. Still my doubts persist as to what is the better alternative.

    Thanks Again.

    Azeem.

  • If your date formats are consistant across your servers and databases then why bother formatting them? I've had to do it in the past to remove the time element, or because we've had a mixture of date formats (due to having US customers talking to our UK servers/databases), but otherwise I tend not to bother.

    As the post I linked to showed, it will slow the query down and if its not required its just more code to read through.

    Personally I'd have a play with it to see if there is any negative impact from removing all of the formatting. If you still get the correct results then do without.

    BrainDonor.

  • Hi

    How to compare Column values with user provided variables.

    Select 1 From tbla Where RID = '13/12/2009'

    or range

    Select 1 From tbla Where RID between '13/12/2009' and '16/12/2009'

    The column contains date and time.

    Thanks

    Azeem

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply