Trigger Prob.

  • Hi!

    I'm trying to make a trigger that is triggered when updating a field.

    In this case I need information of all the columns when information of any column

    is edited.

    e.g.

    I edit the column4 field from value 1 to 10 the trigger makes changes to the

    edit column adding all the unedited information into the edit column in a single line from the

    column1, column2 etc. columns separated with commas.

    [column1] [char](11) NOT NULL, <--primary key

    [column2] [char](1) NULL,

    [column3] [char](1) NULL,

    [column4] [char](2) NULL,

    [column5] [char](1) NULL,

    [edit] [varchar](100) NOT NULL

    Is this even possible?

    =)

  • well, it's pretty straight forward to do in a trigger, but i would just make the [edit] column a calculated field instead and get rid of the trigger idea altogether.

    UPDATE sometable

    SET [edit] = [column1] + ',' + [column2] --etc

    FROM INSERTED

    WHERE sometable.[column1] = INSERTED.[column1]

    but the calculated field would simply be:

    ALTER TABLE sometable ADD [edit] AS [column1] + ',' + [column2] --etc

    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!

  • Thank you

    Gonna try those and see if it suits for these

    people over here =)

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

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