sql server 2008 - Updating table values in a trigger depending on data subset -
ok, title mouthful.
basically, means when dealing rows inserted table, depending on value in specific column, splits rows 1 of 2 subsets, data dealt in 1 of 2 manners. have been iterated on cursor, cte too, there way, following (pseudo) code looks ugly , doesn't work, gives idea of i'm looking for:
trigger
alter trigger [dbo].[tcda_combined_activeunitshiftexpiredstatus_updateshift] on [dbo].[cd_units] after update begin set nocount on if update(shift_start) begin if(inserted.ag_id <> 'fire') begin update cd_units set shift_expired_status = 0 inserted inserted.unid = cd_units.unid , inserted.shift_start <= dbo.get_dts() end else begin update cd_units set shift_expired_status = 0 inserted inserted.unid = cd_units.unid , inserted.shift_start >= dbo.get_dts() end update cd_units set sask911_shift_end = (select substring(shift_start,5,2)+'/'+substring(shift_start,7,2) +' '+substring(shift_start,9,2)+':'+substring(shift_start,11,2) inserted) cd_units join inserted on cd_units.unid=inserted.unid; end end
as always, in advance help
i think main problem here treating inserted
single row, whereas triggers in sql server table level triggers. thus, inserted
table, , can't compare column single value. following.
this part both branches:
update cd_units set shift_expired_status = 0 inserted inserted.unid = cd_units.unid , inserted.shift_start <= dbo.get_dts();
this part updates when inserted.ag_id = 'fire'
:
update cd_units set sask911_shift_end = substring(inserted.shift_start,5,2) + '/' + substring(inserted.shift_start,7,2) + ' ' + substring(inserted.shift_start,9,2) + ':' + substring(inserted.shift_start,11,2) cd_units join inserted on cd_units.unid=inserted.unid inserted.ag_id = 'fire';
Comments
Post a Comment