Re: Append query. letter code to description new but simila

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: HB (HB_at_discussions.microsoft.com)
Date: 01/18/05


Date: Mon, 17 Jan 2005 16:09:03 -0800

John,

I'm sorry my first reponse to previous problem was un-recorded. The Union
clause, while most elegant, is too sophisticated for me, but the Switch was a
big help.

I have a new similar problem, need to turn a field wtih multiple codes (as
opposed to just one code) to multiple rows. Eg: Skills = CO;AG;FB, etc. I
need three rows from that. I started with 3 append queries each with a switch
for each type but it didn't work. It only gave me responses where the skills
field had one code, not multiple.

Thoughts?

I also complemented you on giving such "knowledgable" and elegant advice for
free. You're quite the generous one.

HB

"John Vinson" wrote:

> On Sun, 16 Jan 2005 20:15:03 -0800, "HB"
> <HB@discussions.microsoft.com> wrote:
>
> >Thanks for responding.
> >I don't want to use codes anymore, words are better. And not using a "type"
> >table, using Value List and hard coded values.
>
> Well, a Value List will work, but if you'll ever be changing them, you
> then have a maintenance hassle. A small Table makes a good rowsource
> for a combo box as well, and is easier to maintain. Your choice
> though!
>
> >I don't understand what you wrote re: switch.
>
> Switch() is a builtin function in Access VBA. Type Ctrl-G to open the
> VBA editor (just to get connected to the correct Help file) and select
> Help, and search for Switch() for details. Basically it takes
> arguments in pairs; goes left to right; and when the first member of a
> pair is True it returns the second.
>
> >Part of what makes this difficult is that I am migrating a flat file to a
> >relational table. The flat file is "Transaction" with 30 columns A#, T#, D#
> >where A = amount, T = Type and D= Date. I need to put this into rows. ugh!
> >
> >So, I am writing an append query for each group (ATD), setting criteria for
> >the various types, (D,R, etc.) and then another column as an expression to
> >put the textual description in.
>
> A "Normalizing Union Query" is a very slick way to do this all in one
> swell foop, without needing to set criteria at all.
>
> Let's say Transaction has a field TransID and fields A1 through A30,
> T1 through T30 and so on; and you want to append this data to a
> normalized table with fields TransID, SeqNo (1 to 30), Amount,
> TransType, and TransDate. You can create a Query in the SQL window:
>
> SELECT Transaction.TransID, (1) AS SeqNo, [A1] AS Amount,
> Switch([T1] = "D", "Deposit", [T1] = "W", "Withdrawal",
> [T1] = "P", "Payment", [T1] = "C", "Correction",
> <etc as many pairs as needed>) AS TranType,
> [D1] AS TransDate)
> WHERE [A1] IS NOT NULL
> UNION
> SELECT Transaction.TransID, (2) AS SeqNo, [A2] AS Amount,
> Switch([T2] = "D", "Deposit", [T2] = "W", "Withdrawal",
> [T2] = "P", "Payment", [T2] = "C", "Correction",
> <etc as many pairs as needed>) AS TranType,
> [D2] AS TransDate)
> WHERE [A2] IS NOT NULL
> UNION
> <etcetera, all 30 sets of fields>
>
> Save this Query and then base a UNION query upon it.
>
> John W. Vinson[MVP]
>



Relevant Pages

  • Re: Small Variant Records in C
    ... aligned tightly enough for a `double', you're in trouble. ... union pointer, switched on the common type code, and didn't even ... Along came a compiler that was fairly aggressive (for its time; ... of the cases I'm about to switch between ...
    (comp.lang.c)
  • Re: Append query. letter code to description
    ... I hope my previous reply was recorded, but I'm going to use that switch ... > VBA editor (just to get connected to the correct Help file) and select ... > UNION ... > Save this Query and then base a UNION query upon it. ...
    (microsoft.public.access.queries)
  • Re: Law and Order swan song pretty low key...
    ... but if the series doesn't switch to cable, I guess it won't be too ... The union rep was so over the top that I thought to myself, ... suspect than the actual guy. ...
    (rec.arts.tv)
  • Re: Law and Order swan song pretty low key...
    ... but if the series doesn't switch to cable, I guess it won't be too ... He made a lot more sense as a suspect ... Union rep would have heard all the stories too. ... Yes, I really liked the way they handled her disease in the episode, and I ...
    (rec.arts.tv)
  • Simple Query
    ... Doing a query on tables and we want to order those by date desc.. ... A union would work, but I figured there was a really elegant way to do an ... order by that would accomplish it. ...
    (microsoft.public.sqlserver.programming)