473,398 Members | 2,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Who to return two counts in the recordset?

CroCrew
564 Expert 512MB
Hello Everyone,

Let me start by thanking you all for your help.

Funny but, I have never had the need to return the sum of records in a table for each entity also with that a second column to have a total from a bit field.

Let me explain:

The table has three fields and each record is information for a ticket.
KeyID: an auto incrementing field
MemberID: Integer value
Sold: Bit value (1 is the ticket has been sold)

So for this example let’s say the data looks like this:
1 – 1 – 0
1 – 3 – 1
1 – 2 – 1
1 – 3 – 1
1 – 3 – 0
1 – 2 – 1
1 – 4 – 1
1 – 3 – 1

What I am trying to return from a single query is:
MemberID – TotalTickets – TotalSold
1 – 1 – 0
2 – 2 – 2
3 – 4 – 3
4 – 1 – 1

This is what I have so far. But I can’t figure out how to get the third value to return in the recordset.

SELECT MemberID, COUNT(KeyID) As TotalTickets, '???' As TotalSold
FROM Tickets
GROUP BY MemberID
ORDER BY MemberID


Thanks again for any help that you can give.

CroCrew~
Mar 7 '11 #1
3 1363
gershwyn
122 100+
Maybe I'm misunderstanding your question, but if the sold field can only be 0 or 1, can't you just sum it to get the total?

Expand|Select|Wrap|Line Numbers
  1. SELECT MemberID, COUNT(KeyID) As TotalTickets, SUM(Sold) As TotalSold
  2. FROM Tickets GROUP BY MemberID ORDER BY MemberID
Mar 7 '11 #2
CroCrew
564 Expert 512MB
Sold is a bit data type. A sum operation cannot take a bit data type as an argument.
Mar 7 '11 #3
CroCrew
564 Expert 512MB
Thanks Gershwyn,

You got me thinking.. And this works:

SUM(CAST(Sold as int)) As TotalSold

Thanks again,
CroCrew~
Mar 7 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: zarish | last post by:
hi i am trying to return a recordset from my web service to my c# app. public SQLDataReader getAllCities() { string sqlQuery = "select CityName from city"; SqlCommand comm = new...
19
by: Adam Short | last post by:
I am trying to write a routine that will connect a .NET server with a classic ASP server. I know the following code doesn't work! The data is being returned as a dataset, however ASP does not...
6
by: Alan Silver | last post by:
Hello, I have an ASP that takes a connection string and SQL statement in the querystring and is supposed to return the XML representation of the recordset to the Response stream (don't worry,...
0
by: CSDunn | last post by:
Hello, In Access ADP's that connect to SQL Server databases, any time I have a situation where I have a combo box in a main form that looks up a record in a subform, the subform record source has...
6
by: lenny | last post by:
Hi, I've been trying to use a Sub or Function in VBA to connect to a database, make a query and return the recordset that results from the query. The connection to the database and the query...
13
by: Jan | last post by:
Hi I have a database that I use to keep track of the sales promotions that we send to companies. I normally send a mailing based on a subset of the companies in the database (found using the...
3
by: Ted Ngo | last post by:
I want to use the .net Web Service to create a function and return the datas (RecordSet). And want to retrived those data on the classic ASP. Does any body have some example of this. How to create...
3
by: mark_aok | last post by:
Hi all, All I am trying to do is open a table, edit it, and then close it. But I am having the strangest error. Here is my code Dim i as integer Dim rs as adodb.recordset Set rs = new...
6
by: SethM | last post by:
I have a stored procedure that returns a record set. I want to functionalize this so I can have multiple presentations of the same record set. However, I can not get rs_event.open StoreProc to pass...
4
by: jgoodnight | last post by:
I have a function "ReturnDocumentRules" that returns a recordset. Everything works if I do not close the recordset and set it to nothing, but I know this is bad programming practice. If I do close...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.