The value of variable is disappearing in stored procedure

  • Hi!!!

    The variable is initialized in a stored procedure with the value present in a table.

    It is disappearing at later point of time.The data type of variable is Char.

    Tried to print the value, it displays as NULL.:(

    Please help me...

  • chaturvedi.garima (4/30/2010)


    Hi!!!

    The variable is initialized in a stored procedure with the value present in a table.

    It is disappearing at later point of time.The data type of variable is Char.

    Tried to print the value, it displays as NULL.:(

    Please help me...

    so....are you going to show us the stored procedure? can't really help without that; there must be something changing the data if you say it was initialized to some value, or it was not assigned a value from your table when ou thought it was.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • chaturvedi.garima (4/30/2010)


    Hi!!!

    The variable is initialized in a stored procedure with the value present in a table.

    It is disappearing at later point of time.The data type of variable is Char.

    Tried to print the value, it displays as NULL.:(

    Please help me...

    I second the part of needing to see the code. If there are lots of lines in the code you may need to Keep trying to put print statements in various spots to see what the value is to try by process of elimination find where you're assigning NULL to it.

    ---------------------------------------------------------------------
    Use Full Links:
    KB Article from Microsoft on how to ask a question on a Forum

  • Is it possible that the statement retrieving the value from the table does not actually return a row..? This would make the variable NULL.

    As the other posts have said, we are happy to help if you post your code. 😉

  • Just a shot in the dark without being able to see the code, but if you're using the variable in any concatenation operation, you might want to set the CONCAT_NULL_YIELDS_NULL option off and try it again. With the option on, any concatenation with a NULL will change the entire string to NULL.


    And then again, I might be wrong ...
    David Webb

  • Just FYI, CONCAT_NULL_YIELDS_NULL will always be on in future versions of SQL Server.

    Converting oxygen into carbon dioxide, since 1955.
  • David Webb-200187 (4/30/2010)


    Just a shot in the dark without being able to see the code, but if you're using the variable in any concatenation operation, you might want to set the CONCAT_NULL_YIELDS_NULL option off and try it again. With the option on, any concatenation with a NULL will change the entire string to NULL.

    Oh... absolutely correct but I wouldn't do it that way especially since it's already known that future versions of SQL Server will not have the option of turning it off. Better to use ISNULL() for such things.

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

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