Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Totalling Fields
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01117142
Message ID:
01117147
Vues:
14
Kevin,

You have to check for null on each field:
select isnull(upsell1_order_count, 0) +
       isnull(upsell2_order_count, 0) + ...
    as upsell_qty
...
HTH,
Chad

>I have a table with 25 columns named:
>
>
upsell1_order_count, upsell2_order_count, upsell3_order_count, .... upsell25_order_count
>
>(not my design by the way)
>
>I'm trying to pull all fields totaled together as upsell_qty:
>
>
>select upsell1_order_count +
>       upsell2_order_count +
>       upsell3_order_count +
>       upsell4_order_count + ....
> as upsell_qty
>
>
>Problem is, some of the columns are null, so the resulting value is always null.
>
>I tried:
>
>
>ISNULL(select upsell1_order_count +
>       upsell2_order_count +
>       upsell3_order_count +
>       upsell4_order_count +, 0)
> as upsell_qty
>
>
>But this isn't quite right. I could pull all 25 columns individually and total them up in
>my app, but I'd rather do this in the query, if possible.
>
>Anyone?
_________________________________
There are 2 types of people in the world:
    Those who need closure
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform