Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add Field to SQL Query

Status
Not open for further replies.

netrusher

Technical User
Feb 13, 2005
952
US
What do I need to do with this SQL to show another Field and it values in this query. I would like to add a field
called ProblemIssues to this query and show its values. Can this be done?

Code:
Select FaultCategory, Count(*) As [Faults/NoFaults]
From WorkUnitsFaultsMainTBL
Where [TodaysDate] Between [Forms]![WorkUnitsFaultsMainFRM]![StartDateTxt] And [Forms]![WorkUnitsFaultsMainFRM]![EndDateTxt]
Group By FaultCategory

UNION ALL Select 'Total Work Units', Count(*)
From WorkUnitsFaultsMainTBL
Where [TodaysDate] Between [Forms]![WorkUnitsFaultsMainFRM]![StartDateTxt] And [Forms]![WorkUnitsFaultsMainFRM]![EndDateTxt];

 
Hi!

Since you are using aggregate queries if you add another field you will have to group that that field too. If that is acceptable then by all means add it (assuming of course that it is in the table the query is based on). If you don't want to group by the added field then you may be able to use the query shown as a table in a separate query and link it to the original table and maybe get what you need out that way.

hth


Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
Jeff,

Thanks, but how do I do that? I am fairly new to this so
I do not know how to accomplish this. I have added the
ProblemIssues to the SQL and I get the Column in the Query
but the values are empty.

Allen
 
Code:
Select FaultCategory, Count(*) As [Faults/NoFaults][b][COLOR=red], ProblemIssues[/color][/b]
From WorkUnitsFaultsMainTBL
Where [TodaysDate] Between [Forms]![WorkUnitsFaultsMainFRM]![StartDateTxt] And [Forms]![WorkUnitsFaultsMainFRM]![EndDateTxt]
Group By FaultCategory[b][COLOR=red], ProblemIssues[/color][/b]

UNION ALL Select 'Total Work Units', Count(*)[b][COLOR=red], ProblemIssues[/color][/b]
From WorkUnitsFaultsMainTBL
Where [TodaysDate] Between [Forms]![WorkUnitsFaultsMainFRM]![StartDateTxt] And [Forms]![WorkUnitsFaultsMainFRM]![EndDateTxt]
[b][COLOR=red]GROUP BY [Total Work Units], ProblemIssues[/color][/b]

Randy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top