Convert to datetime from string

  • i have this bit of code:

    if 'TODAY' != upper ('$(runDate)')

    set @RReffectiveRunDate = convert (datetime, '$(runDate)', 120);

    i get an error cannot convert to date / or time from string

    ant ideas??

  • The string "$(runDate)" is not a valid date. And that's not a function or anything, that's a literal string "$(runDate)"

    What are you trying to do?

    Also, this

    if 'TODAY' != upper ('$(runDate)')

    equates to

    if 'TODAY' != '$(RUNDATE)'

    ie, comparing two literal strings (no variables there) and those two literal strings can never be equal.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Is this SQL being compiled by an outside script? If it is we'll need to know what value is in $(runDate) when it's passed to SQL when you're having a problem. If that is the actual value then Gail's post explains what's going on.

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

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