473,396 Members | 2,038 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,396 software developers and data experts.

Data Transform from columns to rows

I have a table that I need to import into access. The table is monthly
data where the month is the column header. I need to transform that
data so that location code, month and number are the only columns.

EX:

Current format

Location
CODE Jan FEB March ...
1 10 12 13
2 7 9 8
-----------------------------------------------------------
Needs to look like

Location
CODE MON #
1 JAN 10
1 FEB 12
1 MAR 13
2 JAN 7
etc.

Jul 25 '06 #1
3 4545
ga*******@gmail.com wrote:
I have a table that I need to import into access. The table is monthly
data where the month is the column header. I need to transform that
data so that location code, month and number are the only columns.

EX:

Current format

Location
CODE Jan FEB March ...
1 10 12 13
2 7 9 8
-----------------------------------------------------------
Needs to look like

Location
CODE MON #
1 JAN 10
1 FEB 12
1 MAR 13
2 JAN 7
etc.
I expect the proponents of and experts in pivot tables will have a much
more efficient answer. I can offer only code:

Dim d As DAO.Database
Dim z As Long
Dim s(0 To 1) As String
Set d = CurrentDb()
s(0) = "SELECT Code, " _
& "'MonthName' AS Mon, " _
& "0 AS Occurrences " _
& "INTO NewTable " _
& "FROM Table3 WHERE 1 = 2"
d.Execute s(0), dbFailOnError
s(0) = "INSERT INTO NewTable SELECT Code, " _
& "'MonthName' AS Mon, " _
& "MonthName AS Occurrences " _
& "FROM Table3"
For z = 1 To 12
s(1) = Replace(s(0), "MonthName", MonthName(z, True))
d.Execute s(1), dbFailOnError
Next z
Set d = Nothing

This is based on the notion that there is only one code 1, code 2 etc.
If there are multiple codes then the sql must be revised to include
sums and groups. It also requires Access 2000 or newer.

Jul 25 '06 #2
Why would you have code lying around to perform such a pointless task?

Look into using arrays to solve this problem, unless A2K3 or better has
a function that does it.

Lyle Fairfield wrote:
ga*******@gmail.com wrote:
I have a table that I need to import into access. The table is monthly
data where the month is the column header. I need to transform that
data so that location code, month and number are the only columns.

EX:

Current format

Location
CODE Jan FEB March ...
1 10 12 13
2 7 9 8
-----------------------------------------------------------
Needs to look like

Location
CODE MON #
1 JAN 10
1 FEB 12
1 MAR 13
2 JAN 7
etc.

I expect the proponents of and experts in pivot tables will have a much
more efficient answer. I can offer only code:

Dim d As DAO.Database
Dim z As Long
Dim s(0 To 1) As String
Set d = CurrentDb()
s(0) = "SELECT Code, " _
& "'MonthName' AS Mon, " _
& "0 AS Occurrences " _
& "INTO NewTable " _
& "FROM Table3 WHERE 1 = 2"
d.Execute s(0), dbFailOnError
s(0) = "INSERT INTO NewTable SELECT Code, " _
& "'MonthName' AS Mon, " _
& "MonthName AS Occurrences " _
& "FROM Table3"
For z = 1 To 12
s(1) = Replace(s(0), "MonthName", MonthName(z, True))
d.Execute s(1), dbFailOnError
Next z
Set d = Nothing

This is based on the notion that there is only one code 1, code 2 etc.
If there are multiple codes then the sql must be revised to include
sums and groups. It also requires Access 2000 or newer.
Jul 25 '06 #3
ManningFan wrote:
Why would you have code lying around to perform such a pointless task?
I didn't. Why would you think I had?

Jul 25 '06 #4

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

Similar topics

2
by: ben moretti | last post by:
hi i'm learning python, and one area i'd use it for is data management in scientific computing. in the case i've tried i want to reformat a data file from a normalised list to a matrix with some...
8
by: Ilan | last post by:
Hi all I need to add data from two Excel sheets (both on the same workbook) to an existing table in my SQL DB. The problem is that each sheet holds different fields for the same record, though...
3
by: Arno R | last post by:
Hi all, I need to transfer a lot of (denormalized) data from Excel To Access. Data is totally wrong formatted for my needs. I need to transform rows and columns. I also need to be able to...
6
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I...
17
by: Justin Emlay | last post by:
I'm hopping someone can help me out on a payroll project I need to implement. To start we are dealing with payroll periods. So we are dealing with an exact 10 days (Monday - Friday, 2 weeks). ...
4
by: Agnes | last post by:
I can export the data to excel, but it is really really slow. need 5-6 mins to export 30 fields (a hundred records) . for my old vfp application, less than 3 minutes. for 500-800 records. Does any...
12
by: JMO | last post by:
I can import a csv file with no problem. I can also add columns to the datagrid upon import. I want to be able to start importing at the 3rd row. This will pick up the headers necessary for the...
1
by: xiao | last post by:
HI~ guys , I have a program here (Sorry it is very long about 240 lines.) It can read and write the header information successfully but it cannot write the array successfully. I guess there is...
4
by: Haas C | last post by:
Hi all, I have a table with two columns, labeled Year and Loss. In the Year field, I have the numbers 1 to 10,000, each which can or cannot repeat. In the Loss column, i have numbers...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.