Sean McGrath
Posts: 371
Joined: 11/3/2020 From: US in NL Status: offline
|
quote:
ORIGINAL: BenG If by rows, depending on what the maximum number of rows for a single wine is, you could partition by the wine, assign row numbers to each row for that wine (ordering by date), then explicitly concatenate the rows - "case when RowNumber = 1 then MasterNote else "" end & case when RowNumber = 2 then MasterNote else "" end ..." etc. You might be able to create a stored procedure to loop through the rows, but I wouldn't know how to do that in Access (haven't used it for a few years). Hi Ben, Believe it or not, I went with a variant of your suggestion. A bit more clunky, as I predetermine the maximum number of notes, but it works very well. Thanks for the idea. I'm sure everyone is desperate to implement this immediately, so I have included the code below. SELECT [Tasting Notes].TastingNotes, [Tasting Notes].TastingDate, [Tasting Notes].iWine, DCount("*","Tasting Notes","iWine = " & [iWine] & " And Int(Date()-[TastingDate]) > " & Int(Date()-[TastingDate]))+1 AS NumNotes, [Tasting Notes].Rating, IIf([NumNotes]=1,[TastingNotes],"") AS Note1, IIf([NumNotes]=2,[TastingNotes],"") AS Note2, IIf([NumNotes]=3,[TastingNotes],"") AS Note3, IIf([NumNotes]=4,[TastingNotes],"") AS Note4, IIf([NumNotes]=5,[TastingNotes],"") AS Note5, IIf([NumNotes]=6,[TastingNotes],"") AS Note6, IIf([NumNotes]=1,[Rating],"") AS Rating1, IIf([NumNotes]=2,[Rating],"") AS Rating2, IIf([NumNotes]=3,[Rating],"") AS Rating3, IIf([NumNotes]=4,[Rating],"") AS Rating4, IIf([NumNotes]=5,[Rating],"") AS Rating5, IIf([NumNotes]=6,[Rating],"") AS Rating6, IIf([NumNotes]=1,[TastingDate],"") AS TasteDate1, IIf([NumNotes]=2,[TastingDate],"") AS TasteDate2, IIf([NumNotes]=3,[TastingDate],"") AS TasteDate3, IIf([NumNotes]=4,[TastingDate],"") AS TasteDate4, IIf([NumNotes]=5,[TastingDate],"") AS TasteDate5, IIf([NumNotes]=6,[TastingDate],"") AS TasteDate6
FROM [Tasting Notes]
WHERE ((([Tasting Notes].iWine)>0))
ORDER BY [Tasting Notes].TastingNotes DESC , [Tasting Notes].TastingDate, [Tasting Notes].iWine;
and of course SELECT [My Notes].iWine, Max([My Notes].NumNotes) AS NumNotes, Max([My Notes].Note1) AS Note1, Max([My Notes].Note2) AS Note2, Max([My Notes].Note3) AS Note3, Max([My Notes].Note4) AS Note4, Max([My Notes].Note5) AS Note5, Max([My Notes].Note6) AS Note6, Max([My Notes].Rating1) AS Rating1, Max([My Notes].Rating2) AS Rating2, Max([My Notes].Rating3) AS Rating3, Max([My Notes].Rating4) AS Rating4, Max([My Notes].Rating5) AS Rating5, Max([My Notes].Rating6) AS Rating6, Max([My Notes].TasteDate1) AS TasteDate1, Max([My Notes].TasteDate2) AS TasteDate2, Max([My Notes].TasteDate3) AS TasteDate3, Max([My Notes].TasteDate4) AS TasteDate4, Max([My Notes].TasteDate5) AS TasteDate5, Max([My Notes].TasteDate6) AS TasteDate6, "[" & [TasteDate1] & " " & [Rating1] & " " & [Note1] & "]" & IIf([NumNotes]>=2,"[" & [TasteDate2] & " " & [Rating2] & " " & [Note2] & "]","") & IIf([NumNotes]>=3,"[" & [TasteDate3] & " " & [Rating3] & " " & [Note3] & "]","") & IIf([NumNotes]>=4,"[" & [TasteDate4] & " " & [Rating4] & " " & [Note4] & "]","") & IIf([NumNotes]>=5,"[" & [TasteDate5] & " " & [Rating5] & " " & [Note5] & "]","") & IIf([NumNotes]>=6,"[" & [TasteDate6] & " " & [Rating6] & " " & [Note6] & "]","") AS MyNote
FROM [My Notes]
GROUP BY [My Notes].iWine;
_____________________________
|