Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

Linux: the choice of a GNU generation -- ksh@cis.ufl.edu put this on Tshirts in '93


devel / comp.databases.ms-access / How to write query to merge group heading to a column

SubjectAuthor
* How to write query to merge group heading to a columnmiloann
`- How to write query to merge group heading to a columnPhilip Herlihy

1
How to write query to merge group heading to a column

<7a3728a7-0944-4c3c-a134-d73de9f04a49n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=1030&group=comp.databases.ms-access#1030

  copy link   Newsgroups: comp.databases.ms-access
X-Received: by 2002:a05:6214:320b:b0:66d:2854:90a8 with SMTP id qj11-20020a056214320b00b0066d285490a8mr64501qvb.3.1697567704177;
Tue, 17 Oct 2023 11:35:04 -0700 (PDT)
X-Received: by 2002:a05:6830:905:b0:6ba:3da9:bf53 with SMTP id
v5-20020a056830090500b006ba3da9bf53mr1084606ott.3.1697567703983; Tue, 17 Oct
2023 11:35:03 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!tncsrv06.tnetconsulting.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.databases.ms-access
Date: Tue, 17 Oct 2023 11:35:03 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=144.166.55.174; posting-account=UJZ3-goAAAA3juC42oL8Xw37Rl6smPhP
NNTP-Posting-Host: 144.166.55.174
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7a3728a7-0944-4c3c-a134-d73de9f04a49n@googlegroups.com>
Subject: How to write query to merge group heading to a column
From: miloann2002@yahoo.com (miloann)
Injection-Date: Tue, 17 Oct 2023 18:35:04 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1359
 by: miloann - Tue, 17 Oct 2023 18:35 UTC

Example:

AAA
123 John Los Angeles
234 Mary San Jose
BBB
345 David San Franscisco
346 Lee Berkely
333 Ann New York
CCC
555 Linda Houston

How to write a query to become:

AAA 123 John Los Angeles
AAA 234 Mary San Jose
AAA 345 David San Franscisco
BBB 346 Lee Berkely
BBB 333 Ann New York
CCC 555 Linda Houston

Thanks

Re: How to write query to merge group heading to a column

<MPG.3f9c6efb82717d57989a89@news.eternal-september.org>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=1031&group=comp.databases.ms-access#1031

  copy link   Newsgroups: comp.databases.ms-access
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: PhillipHerlihy@SlashDevNull.invalid (Philip Herlihy)
Newsgroups: comp.databases.ms-access
Subject: Re: How to write query to merge group heading to a column
Date: Fri, 20 Oct 2023 12:04:19 +0100
Organization: A noiseless patient Spider
Lines: 71
Message-ID: <MPG.3f9c6efb82717d57989a89@news.eternal-september.org>
References: <7a3728a7-0944-4c3c-a134-d73de9f04a49n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="58d606e5e0b8bfb11c22c0f9c667469b";
logging-data="1101733"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX195lavoyeIKP31ixWGlFkXfG8uM49eqlAI="
User-Agent: MicroPlanet-Gravity/3.0.10 (GRC)
Cancel-Lock: sha1:dcht/LbSw9F9cwm/STFIG64soDQ=
 by: Philip Herlihy - Fri, 20 Oct 2023 11:04 UTC

In article <7a3728a7-0944-4c3c-a134-d73de9f04a49n@googlegroups.com>, miloann
wrote...
>
> Example:
>
> AAA
> 123 John Los Angeles
> 234 Mary San Jose
> BBB
> 345 David San Franscisco
> 346 Lee Berkely
> 333 Ann New York
> CCC
> 555 Linda Houston
>
> How to write a query to become:
>
> AAA 123 John Los Angeles
> AAA 234 Mary San Jose
> AAA 345 David San Franscisco
> BBB 346 Lee Berkely
> BBB 333 Ann New York
> CCC 555 Linda Houston
>
> Thanks

This isn't "normalised" data. I can't conceive a query which would do this,
though a real SQL expert possibly might. But I think you could write a macro
to do this in VBA.

Essentially,

- Where there is only one field in a record, store it in a variable.
- Otherwise, read each record, prepend the current contents of the variable,
and write the updated record out.

I'm very rusty with all this these days, but I rather think that "pure" SQL
doesn't recognise "state" - where actions need to be different depending on
what has happened before. I found VBA straightforward enough - though I do
have a long programming background. The library I used in my own coding is DAO,
which provides VBA with facilities to manipulate Access data structures. I
suspect it's rather out-of-date now, though it all still works. I found a
YouTube introduction which seems likely to be helpful, though I haven't had
time to watch more than a minute or so of it: https://www.youtube.com/watch?v=
5SVOxZCCPWw

Sometimes, of course, it's quicker and easier to manipulate modest amounts of
data by hand - open up Excel, put some music on, and (depending on how much
data there is) you could be done by the end of the CD. Unless of course, you
have to process data being sent to you regularly - in which case I'd be leaning
on the source to "normalise" their mucky data.

One other possibility is to process it using "regular expressions" (massively
powerful). The Unix "SED" stream editor utility could do this, as could "AWK",
and RegEx is built into the editor in my copy of Dreamweaver for example. Then
you'd configure the editor to recognise a sequence of non-whitespace characters
terminated by a newline, and store it, prepending that to any lines which
aren't so matched. I haven't fooled around with the Linx Subsystem for
Windows, but that should have SED. Nor have I fooled around with PowerShell
yet - I wonder if that has Regular Expressions? Ah - yes:
https://learn.microsoft.com/en-
us/powershell/module/microsoft.powershell.core/about/about_regular_expressions?
view=powershell-7.3

I _really_ must learn PowerShell...

HTH

--

Phil, London

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor