Stuck on a problem, I have this query
which will give me a result like
vchUser3 vchUser5 vchUser6 vchUser7
--------- ----------- --------- --------
0 0 0 0
5 0 0 0
0 3 0 0
0 0 0 10
0 20 0 0
25 0 0 0
What i need is to be able to sum up the
values of vchUser3 + vchUser5 + vchUser6 + vchUser7
for all rows. These values are also in the database
as strings so they need to formated into integers to
be add them up. I also need to filter out rows with
NULL which is demonstrated in my query.
the result would be 5+25+3+20+10= 63
Is there someway I can change the query so it will
just give me a sum of the all values in the rows
(not the count of rows) ???
Code:
select i.vchUser3, i.vchUser5, i.vchUser6, i.vchUser7
from dbo.Incident i INNER JOIN dbo.Company ON i.iOwnerID = dbo.Company.iCompanyId
where (i.dtInsertDate BETWEEN '3/1/2004' AND '3/31/2004') AND dbo.Company.vchUser2 In (101533,101652)
and I.iIncidentCategory = 3 and i.vchUser3 is not null
which will give me a result like
vchUser3 vchUser5 vchUser6 vchUser7
--------- ----------- --------- --------
0 0 0 0
5 0 0 0
0 3 0 0
0 0 0 10
0 20 0 0
25 0 0 0
What i need is to be able to sum up the
values of vchUser3 + vchUser5 + vchUser6 + vchUser7
for all rows. These values are also in the database
as strings so they need to formated into integers to
be add them up. I also need to filter out rows with
NULL which is demonstrated in my query.
the result would be 5+25+3+20+10= 63
Is there someway I can change the query so it will
just give me a sum of the all values in the rows
(not the count of rows) ???