Date conditions in dynamic sql

  • I'm developing a stored procedure using dynamic sql and I keep getting the following error:  Syntax error converting datetime from character string.

    I'm passing a set of parameters to the sp with defaults

    @ServiceCallStartDate  ='2000-01-01',

    @ServiceCallEndDate  ='2003-12-31'

    In my where clause I have:

    IF @ServiceCallStartDate <> ''

    set @v_Query = @v_Query + ' si.Order_Date > ''' + @ServiceCallStartDate + ''''

    I have other parameters that are char datatypes and this format works fine.

    Please help.

    Thank you

     

     

  • Try This,

    set @v_Query = @v_Query + ' si.Order_Date > ''' + CONVERT(CHAR(10),@ServiceCallStartDate,101) + ''''

     

    Thanks,

     

  • thank you

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

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