Solved

Need to SUM the values in a row

Posted on 2009-05-05
3
528 Views
Last Modified: 2012-06-22
I've got a stored procedure which is working well, it's purpose is to check whether or not a user has enabled or disabled certain parts of a dashboard.  The fields are all tinyint using 1/0 and I'd like to be able to add up those fields to give me a total number of active items.  Here's what I've got so far:

SELECT userShowProcess, userShowLEN, userShowContractExp, userShowWO, userShowTSO, userShowOcc, userShowRev, userShowDelinq, userShowExp
FROM tblUsers
WHERE userID = @UserID;

I'd like to get another field at the end (something like profileOptionsCount) that would add up all the fields that are set to "1" like so:
userShowProcess   userShowLEN   userShowWO   userShowTSO   userShowOcc   userShowRev   userShowDelinq   userShowExp   profileOptionsCount

---------------   -----------   ----------   -----------   -----------   -----------   --------------   -----------   -------------------

1		  0		1            1             1             0             0                0	      4

Open in new window

0
Comment
Question by:saoirse1916
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
ID: 24309738
SELECT      userShowProcess,
      userShowLEN,
      userShowContractExp,
      userShowWO,
      userShowTSO,
      userShowOcc,
      userShowRev,
      userShowDelinq,
      userShowExp,
      userShowProcess + userShowLEN + userShowWO + userShowTSO +
      userShowOcc + userShowRev + userShowDelinq + userShowExp profileOptionsCount
FROM      tblUsers
WHERE      userID = @UserID;
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24309747
By the way you skipped userShowContractExp, was that intentional, otherwise:

SELECT      userShowProcess,
      userShowLEN,
      userShowContractExp,
      userShowWO,
      userShowTSO,
      userShowOcc,
      userShowRev,
      userShowDelinq,
      userShowExp,
      userShowProcess + userShowLEN + userShowContractExp + userShowWO + userShowTSO +
      userShowOcc + userShowRev + userShowDelinq + userShowExp profileOptionsCount
FROM      tblUsers
WHERE      userID = @UserID;
0
 
LVL 8

Author Closing Comment

by:saoirse1916
ID: 31578239
Perfect -- I had no idea it was that simple!  Thanks very much!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now