Case When statement When I assign a string, it say Conversion Failed from varcha

  • CASE can only return one datatype so you will either have to cast everything to varchar(13) or use NULL for No Valid Date.

    ps Instead of typing out '1900-01-01 00:00:00.000' everywhare you can just use '1900'.

    • This reply was modified 3 years, 6 months ago by Ken McKelvey.
  • First of all, you didn't actually post the error you're getting.

    Second, what are the datatypes for all of the columns involved"?  That's actually super important to know here.

    --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)

  • @KenMckelvey thank you. I was resolving it with random integer and your post have given given better response I am after.

    @jeff Modem the Error is in the smaller code block, when you drag to the right 'NO Valid Acceptance Date' to data type int' and data types I pass are DateTime. Sorry really, I tried to edit and remove but I think late in the night I failed. I will edit that now again.

    Also learned that CASE custom column has the same data type as the elements which it is processing.

     

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

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