473,503 Members | 12,175 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

adding values within query

6 New Member
I have a Union Query that is tied directly to a report and one field needs to be modified. The "CountOfAttended" results in a number that needs to have the "Programs.walk-ins" field added to it. This seems like it ought to be a simple thing but every work around I've tried has brought up a variety of errors. The SQL code looks like this (CountOfAttended is highlighted):

SELECT Programs.Name, Programs.[Date Start], Programs.[Date End], Count(Programs__Registered_Participants.Attended) AS CountOfAttended, MonthName(DatePart("m",[Date End])) AS ProgMonth, DatePart("yyyy",[Date End]) AS ProgYear
FROM Programs INNER JOIN (Participants INNER JOIN Programs__Registered_Participants ON Participants.[Participant ID] = Programs__Registered_Participants.Participant_ID) ON Programs.[Program ID] = Programs__Registered_Participants.Program_ID
WHERE (((Programs__Registered_Participants.Attended)=Yes ))
GROUP BY Programs.Name, Programs.[Date Start], Programs.[Date End], DatePart("m",[Date End]), DatePart("yyyy",[Date End])
ORDER BY Programs.Name
UNION SELECT Programs__Tickered_Attendance_ONLY.Name, Programs__Tickered_Attendance_ONLY.Date, Programs__Tickered_Attendance_ONLY.Date, Programs__Tickered_Attendance_ONLY.Attendees, MonthName(DatePart("m",[Date])) AS ProgMonth, DatePart("yyyy",[Date]) AS ProgYear
FROM Programs__Tickered_Attendance_ONLY;


I'm new to SQL of any kind and was handed this somewhat large Access project when a staff member left so I'm taking something over in midstream and a bit lost on how to deal with this problem. Thanks again for any suggestions
Aug 28 '06 #1
2 2649
ADezii
8,834 Recognized Expert Expert
I have a Union Query that is tied directly to a report and one field needs to be modified. The "CountOfAttended" results in a number that needs to have the "Programs.walk-ins" field added to it. This seems like it ought to be a simple thing but every work around I've tried has brought up a variety of errors. The SQL code looks like this (CountOfAttended is highlighted):

SELECT Programs.Name, Programs.[Date Start], Programs.[Date End], Count(Programs__Registered_Participants.Attended) AS CountOfAttended, MonthName(DatePart("m",[Date End])) AS ProgMonth, DatePart("yyyy",[Date End]) AS ProgYear
FROM Programs INNER JOIN (Participants INNER JOIN Programs__Registered_Participants ON Participants.[Participant ID] = Programs__Registered_Participants.Participant_ID) ON Programs.[Program ID] = Programs__Registered_Participants.Program_ID
WHERE (((Programs__Registered_Participants.Attended)=Yes ))
GROUP BY Programs.Name, Programs.[Date Start], Programs.[Date End], DatePart("m",[Date End]), DatePart("yyyy",[Date End])
ORDER BY Programs.Name
UNION SELECT Programs__Tickered_Attendance_ONLY.Name, Programs__Tickered_Attendance_ONLY.Date, Programs__Tickered_Attendance_ONLY.Date, Programs__Tickered_Attendance_ONLY.Attendees, MonthName(DatePart("m",[Date])) AS ProgMonth, DatePart("yyyy",[Date]) AS ProgYear
FROM Programs__Tickered_Attendance_ONLY;


I'm new to SQL of any kind and was handed this somewhat large Access project when a staff member left so I'm taking something over in midstream and a bit lost on how to deal with this problem. Thanks again for any suggestions
I think that your Summary Statistic (Programs__Registered_Participants.Attended) AS CountOfAttended may have to be referenced in the initial GROUP BY Clause. Hope this helps.
ADezii
Aug 28 '06 #2
sluster
6 New Member
I think that your Summary Statistic (Programs__Registered_Participants.Attended) AS CountOfAttended may have to be referenced in the initial GROUP BY Clause. Hope this helps.
ADezii
I explained poorly, the query I posted was working properly, the problem comes in when I try to perform a SUM. For example, it seems to me that this:

Sum(Count(Programs__Registered_Participants.Attend ed), Programs.walk-ins) AS CountOfAttended

In place of this:

Count(Programs__Registered_Participants.Attended) AS CountOfAttended


but when I do that it tells me that subqueries can't be used in this fashion. So that's what I'm trying to figure out, how to add one field to another within this query.

thanks again
Aug 28 '06 #3

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

Similar topics

1
2628
by: Bryan Zash | last post by:
When querying a bit field, I am encountering a problem with MS SQL Server returning a larger number of records for a table than the actual number of records that exist within that table. For...
1
3872
by: Robin Tucker | last post by:
I'm considering adding domain integrity checks to some of my database table items. How does adding such constraints affect SQL Server performance? For example, I have a simple constraint that...
6
9831
by: Wendy Powley | last post by:
I have a subform which represents a 1:N relationship with the main form. I would like to be able to read values from an external file, fill the subform with the values read & allow the user to...
19
59889
by: bdt513 | last post by:
I am trying to extract the values from a query using VBA. Specifically, I want to concatenate all the values of the "rosEmail" field from query "qselRosterEmailList" into one string (strEmails). I...
2
5649
by: Viorel | last post by:
Adding new row with default values. In order to insert programmatically a new row into a database table, without direct "INSERT INTO" SQL statement, I use the well-known DataTable.NewRow,...
6
4400
by: Rudy | last post by:
Hi all, I know this is easy, just can't seem to get it. I have a windows form, and a text box, with a value already in it. I need to add that value to a table. It's just one value, so the entire...
47
3309
by: Pierre Barbier de Reuille | last post by:
Please, note that I am entirely open for every points on this proposal (which I do not dare yet to call PEP). Abstract ======== This proposal suggests to add symbols into Python. Symbols...
0
7896
by: Jeff Boes | last post by:
I hope this helps someone else ... I had struggled some time ago with attempts to get a rank of values query to work, but then I gave up and set it aside. I had another reason to attack it, and in...
3
5337
by: john | last post by:
In my form (table A) I have subform (table B (only 2 fieds: ID and App_name) where table A -Table B are linked 1XM. To be able to add a record in the subform I want to use a lookup form since the...
1
1941
by: OllyJ | last post by:
Hi guys, probably an easy one for you. I know how to limit a row source sor a combo on a form (setting unique values). The problem i'm having is that the query is the record source for a...
0
7067
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
7264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5562
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,...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.