Trigger help!

  • Hi all,

    I am trying to create a trigger that will do the following.

    The Tank table has 3 columns, which are Date, Time, and Mass.

    The trigger will execute if data is inserted into table Tank.

    It will then minus the Mass (the new data) with the last record in Table Tank.

    The difference, date, time and mass will be inserted into another table Difference.

    Can this be done?

    Any help would be appreciated

    Thanks.

  • What if two rows are inserted?

    You need someway to determine what the "order" of the rows i n tank is. Perhaps the date? (assuming this is datetime)

    create trigger ...

    insert difference

    select i.mass - o.mass, i.mass, i.date, i.time

    from inserted i, tank o

    where o.date = ( select max( e.date) from tank e where e.date < i.date)

  • Hi Steve,

    Data is sent from an external device to the server periodically. So it is safe to say that there will be only one row of data inserted at any given time(Well is it 🙂 ). Besides that can SQL server write data to an external file say Excel? Thanks for you help.

  • Hi Steve,

    After doing some searching I found a solution for writing to external file. By using Data Transformation Service. Thanks.

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

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