Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
801 views
in Technique[技术] by (71.8m points)

ms access - Unable to get Allen Browne's ConcatRelated to work on a simple table

I am trying to use the ConcatRelated function to provide a summary report of the prior day's absences, tardies, and vacations. I have tried several variations and can't seem to get it to work in an Access Query. My table looks as below:

ID A_date    Area        ATV_Shift Associate_Name Absent  Tardy Vacation Reason
-- --------- ----------- --------- -------------- ------  ----- -------- --------------
1  1/11/2015 Asm Kenmore First     Keon Wilson         1                 Sick
2  1/11/2015 Asm Kenmore First     Frank Burns         1                 Doctor
3  1/11/2015 Asm Kenmore Second    Paul Mattocks       1                 FLMA
4  1/11/2015 Decoration  First     Jane Doe            1                 Car Broke Down
5  1/11/2015 Asm Maytag  Second    John Doe            1

I need to make a query that displays the previous days data (Date()-1). The reasons need to be separated by spaces. I can get everything else to sum in a query but I am unable to get the reasons to concat. I have tried following the examples but just cant get it to function. I was only able to get it to work using a simple SQL query but that returned lines for each reason not in one cell.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I changed your A_date values to 1/13/2015 and stored those sample data in a table named YourTable. Using that table, this is the output in Access 2010 from the query below.

A_date    SumOfAbsent SumOfTardy SumOfVacation Reasons
--------- ----------- ---------- ------------- -------------------------------
1/13/2015           5                          Car Broke Down Doctor FLMA Sick
SELECT
    y.A_date,
    Sum(y.Absent) AS SumOfAbsent,
    Sum(y.Tardy) AS SumOfTardy,
    Sum(y.Vacation) AS SumOfVacation,
    ConcatRelated(
            'Reason',
            'YourTable',
            'A_date=Date()-1',
            'Reason',
            ' '
        ) AS Reasons
FROM YourTable AS y
WHERE y.A_date = Date()-1
GROUP BY y.A_date;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...