Convert in where clause

  • I see that having a convert in a where clause has some impact on performance when using on VLDBs. Is there any way we could avoid using it. I am mostly doing it for checking on dates ona table which i query often somthing like

     

    select col1, col2 from tab1

    where convert(varchar,createdate,112) =convert(varchar,getdate(),112)

     

    I am trying to avoid this conversion in the where clause without changing the query too much. Is this possible. any solution will be greatly appreciated.

    TIA

     

  • Use 2 datetime variables, and structure it as:

    Declare @StartDate As Datetime

    Declare @EndDate As DateTime

    Select @StartDate = cast(convert(varchar,getdate(),112) As DateTime)

    Select @EndDate = DateAdd(d, 1, @StartDate)

    SELECT

    ...

    WHERE CreateDate >= @StartDate

    AND     CreateDate < @EndDate

     

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

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