You are here: Re: Working with Ints and Nulls « MsSQL Server « IT news, forums, messages
Re: Working with Ints and Nulls

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация