convert - to datetime

  • dd

  • Minnu (11/29/2013)


    Hi Team,

    DECLARE @TEMP VARCHAR(100),

    @DATETIME DATETIME

    SET @TEMP = NULL

    SET @DATETIME = CONVERT(DATETIME,ISNULL(@TEMP,'-'))

    PRINT @DATETIME

    Please help

    What are you trying to achieve? Currently, you're trying to convert the char value "-" into a datetime, which obviously fails.


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • Hi,

    Gettting below error

    The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.

    is there any method to convert '-' to datetime,

    in my scenario, if @temp is null, then '-' should be convert to datetime.

    Please suggest

  • Minnu (11/29/2013)


    Hi,

    Gettting below error

    The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.

    is there any method to convert '-' to datetime,

    in my scenario, if @temp is null, then '-' should be convert to datetime.

    Please suggest

    How would "-" be a datetime data type? Where is the year, month, day etc ?

    My assumption is that what you are doing is attempting to display this in a front end application or in SSRS, would that be correct? I'd suggest that you handle the NULL value in the presentation layer rather than in the database.


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • Minnu (11/29/2013)


    dd

    How rude. It's just totally improper to delete the original post even if things don't work out exactly as you planned.

    If you still need an answer on this, please restore the original question.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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