Is grouping on tablename possible?

I haven't worked with Crystal Reports for several years.   I wanted to ask a general question regarding table joins within the query for a crystal report.   I have 5 tables, with identical fields that I query using a UNION ALL statement.  I group the data by the fields and summarize.   Pretty straight forward.   However, I was wondering if there was a way to identify (without separating in separate reports) the tables... basically grouping on this information and then drilling down to group on the field information.     If you need to see code examples, please let me know.
mojeauxBusiness UserAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
Sure.. modify your data source e.g.

SELECT 'TableA' AS TableName, * FROM TableA
UNION
SELECT 'TableB' AS TableName, * FROM TableB
ORDER BY TableName;

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mlmccCommented:
That would work.  Assuming you are using a COMMAND for the data.

Can you modify the tables to include a column with the table name?

mlmcc
mojeauxBusiness UserAuthor Commented:
Wow that was super easy.   lol   Thanks Ste5an.   Sorry, LVL101 I am only able to retrieve data from the tables for reporting.  

Once I name the tables in the Command Query,  I can then choose the field from the tablename to group on.  Correct?
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

ste5anSenior DeveloperCommented:
Yup.
mojeauxBusiness UserAuthor Commented:
When I change my query to assign table names, Crystal grouping doesn't recognize it.  It still refers to the grouping field as query.field.
SELECT ATTR0000002000 as STREET,
   ATTR0000002001 as ADDRESS,
   ATTR0000002011 as CITY,
   ATTR0000002021 as STATE,
   ATTR0000002031 as ZIP,
   VERSIONID,
   CREATETS,
   LASTCHANGEDUSERID
FROM EXAMPLE.IXXXX02326001 AS ORDERS
WHERE CREATETS > CURRENT TIMESTAMP - 7 DAYS
   UNION ALL
SELECT ATTR0000002000 as STREET,
   ATTR0000002001 as ADDRESS,
   ATTR0000002011 as CITY,
   ATTR0000002021 as STATE,
   ATTR0000002031 as ZIP,
   VERSIONID,
   CREATETS,
   LASTCHANGEDUSERID
FROM EXAMPLE.IXXXX02324001 AS EXPENSES
WHERE CREATETS > CURRENT TIMESTAMP - 7 DAYS
ste5anSenior DeveloperCommented:
hmm, what about

SELECT 'ORDERS' AS TableName,
   ATTR0000002000 as STREET,
   ATTR0000002001 as ADDRESS,
   ATTR0000002011 as CITY,
   ATTR0000002021 as STATE,
   ATTR0000002031 as ZIP,
   VERSIONID,
   CREATETS,
   LASTCHANGEDUSERID
FROM EXAMPLE.IXXXX02326001 AS ORDERS
WHERE CREATETS > CURRENT TIMESTAMP - 7 DAYS
   UNION ALL
SELECT 'EXPENSES' AS TableName,
   ATTR0000002000 as STREET,
   ATTR0000002001 as ADDRESS,
   ATTR0000002011 as CITY,
   ATTR0000002021 as STATE,
   ATTR0000002031 as ZIP,
   VERSIONID,
   CREATETS,
   LASTCHANGEDUSERID
FROM EXAMPLE.IXXXX02324001 AS EXPENSES
WHERE CREATETS > CURRENT TIMESTAMP - 7 DAYS 

Open in new window


Please use the CODE button to embed code.
mojeauxBusiness UserAuthor Commented:
Thanks!   This was a huge timesaver.   Appreciate the QUICK assist.    =)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.