Originally posted by kyjabber
Can you post the SQL you used as well as the actual code (if different at all from my posted code).
CompanyName Category Product CompanyName1 Fruit Pears CompanyName1 Vegetables Cabbage CompanyName2 Organics Eggs CompanyName3 Vegetables Beets CompanyName3 Meats Turkey
Option Compare Database
'Concat Returns Products
'listed by company
Public Function Concat(strCompanyName As String, _
strProduct As String) As String
Static strLastCompanyName As String
Static strProducts As String
If strCompanyName = strLastCompanyName Then
strProducts = strProducts & ", " & strProduct
Else
strLastCompanyName = strCompanyName
strProducts = strProduct
End If
Concat = strProducts
End Function
SELECT [CompanyName], [Category], Max(Concat([CompanyName] & [Category],[Product])) AS Products FROM t_CompanyCategoriesProducts GROUP BY [CompanyName], [Category];
CompanyName Category Product "R"" Farm Vegetables Pumpkins 4-H Nursery Vegetables Tomatoes A Winery & Restaurant Fruits Grapes A Winery & Restaurant Vegetables Beans A Winery & Restaurant Vegetables Beets A Winery & Restaurant Vegetables Broccoli A Winery & Restaurant Vegetables Brussel Sprouts A Winery & Restaurant Vegetables Cabbage Ay Farm Vegetables Beans Ay Farm Vegetables Cucumber Ay Farm Vegetables Green Onions Ay Farm Vegetables Okra Ay Farm Vegetables Peppers Ay Farm Vegetables Rhubarb Ay Farm Vegetables Sweet Corn Aly Farm Vegetables Tomatoes Aly Farms Fruits Melons Aly Farms Fruits Watermelons Aly Farms Meats Beef Aly Farms Vegetables Beans Aly Farms Vegetables Cucumber Aly Farms Vegetables Eggplant Aly Farms Vegetables Lettuce Aly Farms Vegetables Okra Aly Farms Vegetables Peppers
SELECT t_CompanyCategoriesProducts.CompanyName, t_CompanyCategoriesProducts.Category, Last(Concat([CompanyName] & [Category],[Product])) AS Products FROM t_CompanyCategoriesProducts GROUP BY t_CompanyCategoriesProducts.CompanyName, t_CompanyCategoriesProducts.Category;
SELECT t_CompanyCategoriesProducts.CompanyName, t_CompanyCategoriesProducts.Category, Last(Concat([CompanyName] & [Category],[Product])) AS Products FROM t_CompanyCategoriesProducts GROUP BY t_CompanyCategoriesProducts.CompanyName, t_CompanyCategoriesProducts.Category;
Comment