|  | Posted by Shuurai on 12/05/06 20:39 
Hurricane wrote:> I have an instead of trigger for update on particular table which adds
 > 3 or so columns and puts the total in a 4th No matter what the input is
 > (as long as there is one NULL) the total is always NULL. More than
 > likely is that only one of the fields has a value in it and the rest
 > null but i don't want to do the MAX in case that is not true.
 >
 >
 > a quick visual aid from input and desired output
 >
 > Input Data
 > colA   colB    ColC  tot
 >   5      NULL  NULL NULL
 >
 > Current Output
 > colA   colB    ColC  tot
 >   5      NULL  NULL NULL
 >
 > Desired Output
 > colA   colB    ColC  tot
 >   5      NULL  NULL 5
 >
 > How do i Manipulate the TSQL command to work correctly?
 
 Forget about the triggers and create a view:
 
 
 /*
 ----------------------------------------------------------------------------------*/
 create view vwWhatever as
 select isnull(colA, 0) as colA,
 isnull(colB, 0) as colB,
 isnull(colC, 0) as colC,
 isnull(colA, 0) + isnull(colB, 0) + isnull(colC, 0) as tot
 from
 YourTable
 
 /*
 ----------------------------------------------------------------------------------*/
 
 There is no reason to store the total, it is redundant.
  Navigation: [Reply to this message] |