• sharonsql2013 (7/5/2013)


    Hi

    I declared the primary key as identity int.

    Now everytime a value(code) is selected from the grid , I want a corresponding character to be concatenated to the primary key( integer) and stored in another column.

    Example : if code = student then add "S" to "1" and store S1 to another column.

    else if code = Teacher then add "T" to 2 and store T2.

    How should I implement this logic?

    You probably shouldn't. Storing such data is a violation of even first normal form. At best, creating a view, as already suggested, might be the better way to go but make sure you don't use the concatenated column in a lookup or it's likely the whole view will need to materialize before you can get an answer from it.

    Why do you want/need to do this? What business process requires the concatenation?

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