473,425 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,425 software developers and data experts.

New to access. stumped on query. Column to Row conversion Any ideas?

Hey everyone,

I have never really used access before and i now find myself knee deep
in it trying to solve a problem. Hopefully someone has an idea.
Anything would be great. Here's the problem:

I am working on a network invrntory solution for my department.
We're using a great little utility to audit each machine on the
network, storing all kinds of information about hardware and software
in an access database on one of the public network drives. The program
formats the table in a slightly funky way. One column contains the
primary key (just a number corresponding to each unique bit of
inormation which has been audited) and the second coulmn contains the
actual audit information (for example text describing the amount of
memory, the version of windows etc.)
I have been trying to find a way to convert the entries of the
second colum into a single record (new table), using the first entry of
the second colum (computer name) as the primary key. I have yet to find
a way to do this, but i'm sure it can be done. My SQL skills are
limited to say the least. Any ideas would be great. Thanks!

Sam

Dec 9 '05 #1
2 1583
He******@gmail.com wrote in
news:11*********************@g44g2000cwa.googlegro ups.com:
Hey everyone,

I have never really used access before and i now find myself
knee deep
in it trying to solve a problem. Hopefully someone has an
idea. Anything would be great. Here's the problem:

I am working on a network invrntory solution for my
department.
We're using a great little utility to audit each machine on
the network, storing all kinds of information about hardware
and software in an access database on one of the public
network drives. The program formats the table in a slightly
funky way. One column contains the primary key (just a number
corresponding to each unique bit of inormation which has been
audited) and the second coulmn contains the actual audit
information (for example text describing the amount of memory,
the version of windows etc.)
I have been trying to find a way to convert the entries of
the
second colum into a single record (new table), using the first
entry of the second colum (computer name) as the primary key.
I have yet to find a way to do this, but i'm sure it can be
done. My SQL skills are limited to say the least. Any ideas
would be great. Thanks!

Sam

Easily done in Visual Basic using a recordset, but a PITA using
SQL.

First step is to get a list of all possible field names
Use this to create the new table. (note: code not debugged may
contain typos)

Dim rs1 as recordset
dim strSQL as string.
set rs1 = currentdb.openrecordset("SELECT DISTINCT column2 from
Funkytable;")

do until rs1.EOF
strSQL = (strSQL + ", ") & rs1!column2 & " Char"
rs1.movenext
LOOP
strSQL = "CREATE TABLE NewName (" & StrSQL & ");"
currentdb.execute strSQL
rs1.close

then walk the original reading each column2 and column3, writing
the column3 value to the column2

Dim rs1 as recordset
dim strSQL as string.
dim strFields as string
dim strValues as string.
set rs1 = currentdb.openrecordset("SELECT * from Funkytable
ORDER BY [primary key];")
do until rs1.EOF
strfields = (strfields + ", ") & rs1.column2
strValues = (strValues + ", """) & rs1.column3 & """"
rs1.movenext
if rs1.EOF then Exit DO 'goto LAST_1
if rs1.column2 = "Computer Name" then
strSQL = "INSERT INTO newtable (" _
& strfields & ") VALUES (" _
& strValues & ");"
currentdb.execute strSQL
strfields = ""
strValues = ""
endif
loop
Last_1:
strSQL = "INSERT into newtable fields (" _
& strfields & ") VALUES (" _
& strValues & ");"
currentdb.execute strsql
rs1.close
Work on a copy of your database until you are comfoirtable that
the code works.
--
Bob Quintal

PA is y I've altered my email address.
Dec 10 '05 #2
If the Computer gets audited more than once in it's life you might not want
ComputerName to be the Primary Key unless you don't care about a history and
will be replacing the values.

You might also consider having two fields from this table instead of creating
a field for each original record in the funky table ...

ComputerName
AuditInfo

Actually I would think something like:

table = tblComputers with fields = ComputerName, CompLocation, CompPurchased,
etc.
table = tblAudits with fields = AuditID, ComputerName, AuditDate, AuditNotes,
etc.
table = tblAuditDetails with fields = AuditDetailID, AuditID, AuditInfo

A separate record for each audit info, would make sense if it is all text.
If the audit info reports would create different fileds in different
situations then this would make it easy to combine the info from different
computers - the fields would all be the same ...

Hope this helps,
Roger

He******@gmail.com wrote:
Hey everyone,

I have never really used access before and i now find myself knee deep
in it trying to solve a problem. Hopefully someone has an idea.
Anything would be great. Here's the problem:

I am working on a network invrntory solution for my department.
We're using a great little utility to audit each machine on the
network, storing all kinds of information about hardware and software
in an access database on one of the public network drives. The program
formats the table in a slightly funky way. One column contains the
primary key (just a number corresponding to each unique bit of
inormation which has been audited) and the second coulmn contains the
actual audit information (for example text describing the amount of
memory, the version of windows etc.)
I have been trying to find a way to convert the entries of the
second colum into a single record (new table), using the first entry of
the second colum (computer name) as the primary key. I have yet to find
a way to do this, but i'm sure it can be done. My SQL skills are
limited to say the least. Any ideas would be great. Thanks!

Sam


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200512/1
Dec 10 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Russell | last post by:
I'm having a fit with a query for a range of dates. The dates are being returned from a view. The table/field that they are being selected from stores them as varchar and that same field also...
19
by: Dan. | last post by:
hi there, a while back i got into a bit of ASP programming and needed database access. since msAccess was installed on the system i was using at the time i used that and have used that since. but...
7
by: Thomi Baechler | last post by:
Hello Everybody I run the following query against to identical databases. Execution time on the first DB is 0 seconds, on the other 6 seconds! SELECT dbo.HRMABZ.EMPKEY ,...
1
by: gary.scott | last post by:
Aaaaaarrgghh ! (that's better) I am trying to convert a field within my Oracle 9i Database that is of type BLOB (but this BLOB may contain a combination of clobs/varchars or images such as gif...
1
by: jfallara | last post by:
Hi all, kind of new to Access, but I'm learning as I go. What I'm currently trying to do is take data from an Excel spreadsheet and transfer it into an Access database with mutiple linked tables....
8
by: s_wadhwa | last post by:
SELECT DISTINCTROW "01C" AS dummy, Buildings.BuildingNumber, UCASE(Buildings.BuildingName) AS BuildingName, Buildings.MasterPlanCode, Buildings.UniformBuildingCode,...
15
by: Hexman | last post by:
Hello All, How do I limit the number of detail records selected in a Master-Detail set using SQL? I want to select all master records for a date, but only the first 3 records for the details...
14
by: awayne | last post by:
I am working with MS VB 6.5. I am putting together a MS Access (MS Access 2000) database for work to keep track of the projects and their status that we've done. I use MS Access to run a "Make-table...
2
by: Andy | last post by:
Hi guys I having a problem creating a report in Access 2003 project talking to a SQL database through and ODBC connect. After hours of trying things from Access Help, MSDN and Google I still...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.