dbTalk Databases Forums  

SQL in Access Report

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss SQL in Access Report in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
AT
 
Posts: n/a

Default SQL in Access Report - 04-25-2006 , 05:34 PM






I have one table used to maintain information on Service Events.
Each record contains a Repair, Maint, and Battery checkbox
(bound/boolean). Any one of these fields may be checked or left empty.
Ex. REPAIR=True, MAINT=False, BATTERY=True

I want to generate ONE report that lists all the REPAIRS, then lists
all the MAINT, and then lists all the BATTERY events. One group after
the other in the same report. Because (ex. REPAIR and BATTERY) may
both be true in the same record, the record will appear 2 times in the
report, once in the REPAIR group and once in the BATTERY group.

I am not sure how to approach this. I'm new to SQL. I' m using MS
AccessSQL.

I Tried the following code, but the results are not sorting properly
and not grouped.

SELECT * FROM [TABLE1] WHERE [REPAIR]
UNION ALL
SELECT * FROM [TABLE1] WHERE [MAINT]
UNION ALL
SELECT * FROM [TABLE1] WHERE [BATTERY]


Reply With Quote
  #2  
Old   
MGFoster
 
Posts: n/a

Default Re: SQL in Access Report - 04-25-2006 , 06:11 PM






-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You don't need a UNION query, just a regular SELECT

(Access SQL syntax)

SELECT IIf(repair=True,"Repair",
IIf(battery=True,"Battery",
IIf(maint=True,"Maint","Unknown") As GroupByThis,
repair,
maint,
battery,
<other columns>
FROM table1
WHERE <some criteria>

Set up your report using the Grouping/Sorting dialog box

(menu bar: View > Sorting and Grouping)

Select the GroupByThis column in the Field/Expression column of the
dialog box. Set the Group Header to Yes. Place the GroupByThis column
in the Group Header column. If you want to put totals for each
grouping, set the Group Footer to Yes and set up =Sum() Text Boxes.

Now the report is set up to group each GroupByThis value.

For more info on creating report groups see the Access Help articles
under table of contents heading

Reports and Report Snapshots
Sorting and Grouping Records in a Report

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRE6sgoechKqOuFEgEQI3YACeK41dgagIW4yD/7FgbdGQXTPX3jUAoKzC
g5e9onkszM/TwkfuX0UVVC7H
=SF3w
-----END PGP SIGNATURE-----


ApexData (AT) gmail (DOT) com wrote:
Quote:
I have one table used to maintain information on Service Events.
Each record contains a Repair, Maint, and Battery checkbox
(bound/boolean). Any one of these fields may be checked or left empty.
Ex. REPAIR=True, MAINT=False, BATTERY=True

I want to generate ONE report that lists all the REPAIRS, then lists
all the MAINT, and then lists all the BATTERY events. One group after
the other in the same report. Because (ex. REPAIR and BATTERY) may
both be true in the same record, the record will appear 2 times in the
report, once in the REPAIR group and once in the BATTERY group.

I am not sure how to approach this. I'm new to SQL. I' m using MS
AccessSQL.

I Tried the following code, but the results are not sorting properly
and not grouped.

SELECT * FROM [TABLE1] WHERE [REPAIR]
UNION ALL
SELECT * FROM [TABLE1] WHERE [MAINT]
UNION ALL
SELECT * FROM [TABLE1] WHERE [BATTERY]


Reply With Quote
  #3  
Old   
AT
 
Posts: n/a

Default Re: SQL in Access Report - 04-25-2006 , 07:06 PM



Thanks for the response.

I took your advice and tried the following code:

SELECT IIf([RPR]=True,"RPR",
IIf([MNT]=True,"MNT",
IIf([BAT]=True,"BAT","Unknown"))) AS GroupByThis,
[RPR],
[BAT],
[MNT],
*
FROM [T-SERVICE];

The repairs have grouped just fine, but the battery and maint will only
group with records that are not already displayed in the repairs group.

Any further advice?


Reply With Quote
  #4  
Old   
MGFoster
 
Posts: n/a

Default Re: SQL in Access Report - 04-25-2006 , 09:24 PM



ApexData (AT) gmail (DOT) com wrote:
Quote:
Thanks for the response.

I took your advice and tried the following code:

SELECT IIf([RPR]=True,"RPR",
IIf([MNT]=True,"MNT",
IIf([BAT]=True,"BAT","Unknown"))) AS GroupByThis,
[RPR],
[BAT],
[MNT],
*
FROM [T-SERVICE];

The repairs have grouped just fine, but the battery and maint will only
group with records that are not already displayed in the repairs group.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You may have to go back to your original UNION query, with the addition
of a GroupByThis column. E.g.:

SELECT "RPR" As GroupByThis, *
FROM [T-Service]
WHERE [RPR] = True
UNION
SELECT "BAT" As GroupByThis, *
FROM [T-Service]
WHERE [BAT] = True
UNION
SELECT "MNT" As GroupByThis, *
FROM [T-Service]
WHERE [MNT] = True
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRE7ZwIechKqOuFEgEQKwrwCg4/+EDv8jV+47+CAGLaCoH/WDcCMAni3n
Dx9Xa1Cla3dw3zNvYjxuoxXA
=45Cm
-----END PGP SIGNATURE-----


Reply With Quote
  #5  
Old   
AT
 
Posts: n/a

Default Re: SQL in Access Report - 04-25-2006 , 10:18 PM



THAT WORKED !!!

Thankyou Very Much. I spent a long time on this one.
Your advice was right on target. Someone else also had
recommended a similar solution in another group, but it just
took time to sink in.

Thanks Again


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.