DATEADD Function Problem

  • When I run this query in QA:

    SELECT DATEADD(

     SUBSTRING(FREQUNIT,1,LEN(FREQUNIT)-1),

     FREQUENCY,

     pm11)

    FROM PM

    I receive this error:

    Server: Msg 1023, Level 15, State 1, Line 4 Invalid parameter 1 specified for dateadd.

    Can anyone tell me what I'm doing wrong?

    frequnit = DAYS, WEEKS, MONTHS or YEARS. The substring function strips the 'S' off the end.

    frequency is an integer field.

    pm11 is a datetime field.

     

    TIA...Paul

  • Dateadd does not work like in vb where the first paramtere is a string input. It actually now is a constant, so you have to use s not 's' to work. If you need to be able to adjust on the fly then you will need to create a user defined function to accept a varchar to cover first parameter option, value, and date input then based on the varchar use if logic to process the date under the right dateadd. On my way out but if you need help I can give you an example tomorrow.

  • Thanks, Antares686...

    That answered my question. Now I know what I need to do to solve it from here.

    I appreciate your help!!!

    Paul

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

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