In my example syntax below I want the field
delayed to be the difference in days between
dunitdate I know that this syntax will get me the result, and I was going to set this up as an
OnInsert() and a
AfterUpdate() trigger however my two fields are not required! I can not alter table structure to make them be required.
Question at hand, how can I use this update syntax to account for a null date, to update to 0 if either field is null or update to the
DateDiff() if both fields are not null? And as always, if there is a better approach for this methodology I am open to suggestions:
Create Table #Moofasa ( gotitdate date ,dunitdate date ,delayed int ) Insert Into #Moofasa (gotitdate, dunitdate) Values ('07/01/2016','07/05/2016') ,('07/01/2016','07/04/2016') ,('07/04/2016','07/08/2016') Update #Moofasa Set delayed = DateDiff(d, gotitdate, dunitdate) WHERE delayed is null Select * from #Moofasa --Drop Table #Moofasa