Variable legnth violation

  • Greetings folks. I have a procedure for emailing, where there is a variable to house the content of the body, @body VARCHAR(1000). I saw where one of the emails on a particularly busy day of production was truncated, so I went to adjust the legnth of @body to 4000, and just for fun I copied the entire body of the email, then queried SELECT LEN('my pasted email body'). Lo and behold, the length was 1016. How is this possible if I have explicitly declared the variable to be 1000?

    Greg

    Greg
    _________________________________________________________________________________________________
    The glass is at one half capacity: nothing more, nothing less.

  • LEN does not include trailing spaces... try the same thing with DATALENGTH.

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

  • Jeff, same thing with DATALENGTH. Its not a big deal, just one of those things I don't get. I don't know if it matters, but when I copied and pasted the text from the body of the email, the blue background extended 6 spaces past the end of the truncated text.

    Greg

    Greg
    _________________________________________________________________________________________________
    The glass is at one half capacity: nothing more, nothing less.

  • Greg... stupid question on my part, but have you tried using RTRIM to get rid of the trailing spaces?

    --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 4 posts - 1 through 3 (of 3 total)

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