Re: Move from one table to other table in a different format

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



On Fri, 4 Apr 2008 17:57:24 -0700 (PDT), "learning_codes@xxxxxxxxxxx"
<learning_codes@xxxxxxxxxxx> wrote:

TABLE #1
OrderID Product A Product B Product C........... up to 100
1 Mon Wed
Fri Mon to Fri
2 Tues Fri
Thurs Mon to Fri


TABLE#2 (This is what I need to set this format)
OrderID InStock Mon Tues Wed Thurs
Friday
1 Product A Yes No No
No No
1 Product B No No Yes
No No

I'd suggest you go a step further in normalization. Having fields named Mon
Tues Wed Thurs Fri is just as bad as having fields named Product A Product B!
You shouldn't be storing data in fieldnames at all.

A better design would be:

OrderID
Product
DayInStock

The DayInStock function could be the day name, or maybe better an integer with
values 1 to 7 (or 2 to 6 if weekends are never an issue) to go along with
the Weekday function, value 1 = Sunday, 7 = Saturday.

It will help if you have a days translation table DayTable, fields DayList and
DayInStock with records like

Mon 2
Tue 3
Wed 4
....
Mon to Fri 2
Mon to Fri 3
Mon to Fri 4
Mon to Fri 5
Mon to Fry 6
Mon to Tue 2
Mon to Tue 3
<all possible used combinations>

You can then use a Normalizing Union Query like:

SELECT Table1.OrderID, DayTable.DayInStock, "Product A" AS Product
FROM Table1 INNER JOIN DayTable
ON Table1.[Product A] = DayTable.DayList
UNION ALL
SELECT Table1.OrderID, DayTable.DayInStock, "Product B" AS Product
FROM Table1 INNER JOIN DayTable
ON Table1.[Product B] = DayTable.DayList
UNION ALL
SELECT Table1.OrderID, DayTable.DayInStock, "Product C" AS Product
FROM Table1 INNER JOIN DayTable
ON Table1.[Product C] = DayTable.DayList

<etcetera>

You probably won't get all 100 fields without getting the QUERY TOO COMPLEX
error, but you can do 25 fields at a time, I suspect.

Base an Append query on this to populate the tall-thin normalized table; if
you need the grid with day names as the header row, create a Crosstab query
based on the tall-thin.

If the days actually correspond to real-life dates, I'd take it yet a step
further and have a Date/Time field.
--

John W. Vinson [MVP]
.



Relevant Pages

  • Re: Non-updateable query issue
    ... The issue arises when I create the query for the datasheet view to ... master table primary key. ... I am a big fan of normalization. ... Say Fred deletes record 79 from Table1, ...
    (microsoft.public.access.queries)
  • RE: Processing thousands of records
    ... Jerry Whittle, Microsoft Access MVP ... Access automatically creates an index for primary key fields. ... that the query is working faster, you don't need the 1stVisit02 query. ... where do I read about fundamental indexing and normalization? ...
    (microsoft.public.access.queries)
  • RE: Processing thousands of records
    ... Access automatically creates an index for primary key fields. ... that the query is working faster, you don't need the 1stVisit02 query. ... Jerry Whittle, Microsoft Access MVP ... where do I read about fundamental indexing and normalization? ...
    (microsoft.public.access.queries)
  • RE: Normalization woes - how do I reproduce a query?
    ... I would use a standard select query with code in the web page to manage ... I can now appreciate the advantages of normalization but cannot reproduce ... FROM Lodging INNER JOIN IconAssignments ON Lodging.LodgingID = ... and records that had no assigned icons didn't appear at all. ...
    (microsoft.public.access.queries)
  • Re: Syntax for FROM tablename on a form
    ... >What doesn't work is to recognize the FROM target from the form. ... There are many reasons why you ... executing an Update query). ... If you are unable to rectify the normalization issues, ...
    (microsoft.public.access.forms)