I know that subject probably did not adequately explain anything so here
goes...
I have an access file that needs to be transposed from its current format to
a new format so that I can then export as a flat file to be imported into a
shopping cart. This file is to create a set of attributes/options for each
product.
The file I have is in a pretty standard format:
Prod_Code | ATTR_CODE | OPT1 | OPT2 | OPT3 | OPT4 | OPT5
0037 | Color | RED | GREEN |YELLOW |BROWN | BLUE
0037 | Size | SMALL | MED | LARGE | |
The above represents the single product with code 0037. The intended result
is just what one would assume. 2 selectable attributes, color and size and
each with their sub options (5 possible colors and 3 possible sizes).
Ok, the problem is the flat file needs to be structured thusly:
Prod_Code | ATTRCODE | OPTCODE
0037 | Color |RED
0037 | Color |GREEN
0037 | Color |YELLOW
0037 | Color |BROWN
0037 | Color |BLUE
0037 | Size |SMALL
0037 | Size |MED
0037 | Size |LARGE
The software expects incoming data to be one line at a time like that.
So, I need to revamp the structure of this table to make a new line every
time a value in one of the "OPTx" fields is encountered - copying over
whatever values were found in Prod_Code and ATTR_CODE and with the new
column OPTCODE to hold the values removed from the multiple OPTx columns.
It should be noted that some product's attributes have up to 14 options so
it goes all the way to OPT14.
What magical spell must I cast to get where I need to go? Thanks much. 8 1798
I would probably use a visual basic routine that reads each record from your
table, and then writes a record to another table for each option code found
in the read record.
Here is some untested code (that I'm sure has errors) that will hopefully
give you some ideas.
first make a table "yourOutputTable", with three fields: Prod_code,
Attr_code, and Option_code
Dim rstInput As DAO.Recordset
Dim rstOutput As DAO.Recordset
dim lngProdCode as long
dim strAttCode as string
dim i as int
dim strOptionCode as string
Set rstInput = CurrentDb.OpenRecordset("YourInputTable")
Set rstOutput = CurrentDb.OpenRecordset("YourOutputTable")
rstInput .MoveFirst
Do While Not rstInput .EOF
lngProdCode = rstInput ("Prod_Code")
strAttCode = rstInput ("Attr_Code")
for i = 3 to 14
'stop if you get to a null field, assuming once you get to a
null, there are no more after that
if isnull (rstInput.fields(i) ) then
exit for
end if
rstOutput .AddNew
rstOutput ("Prod_Code") = lngProdCode
rstOutput ("Attr_Code") = strAttCode
rstOutput ("Option_Code") = rstInput.fields(i)
rstto.Update
next i
rstInput.MoveNext
Loop
rstInput.close
rstOutput.close
Set rstInput = Nothing
Set rstOutput = Nothing
Hope this helps
-John I know that subject probably did not adequately explain anything so here goes...
I have an access file that needs to be transposed from its current format to a new format so that I can then export as a flat file to be imported into a shopping cart. This file is to create a set of attributes/options for each product.
The file I have is in a pretty standard format:
Prod_Code | ATTR_CODE | OPT1 | OPT2 | OPT3 | OPT4 | OPT5 0037 | Color | RED | GREEN |YELLOW |BROWN | BLUE 0037 | Size | SMALL | MED | LARGE | |
The above represents the single product with code 0037. The intended result is just what one would assume. 2 selectable attributes, color and size and each with their sub options (5 possible colors and 3 possible sizes).
Ok, the problem is the flat file needs to be structured thusly:
Prod_Code | ATTRCODE | OPTCODE 0037 | Color |RED 0037 | Color |GREEN 0037 | Color |YELLOW 0037 | Color |BROWN 0037 | Color |BLUE 0037 | Size |SMALL 0037 | Size |MED 0037 | Size |LARGE
The software expects incoming data to be one line at a time like that.
So, I need to revamp the structure of this table to make a new line every time a value in one of the "OPTx" fields is encountered - copying over whatever values were found in Prod_Code and ATTR_CODE and with the new column OPTCODE to hold the values removed from the multiple OPTx columns. It should be noted that some product's attributes have up to 14 options so it goes all the way to OPT14.
What magical spell must I cast to get where I need to go? Thanks much.
John Welch <john(remove)welch@cal(remove)central.com> wrote:
<preliminaries snipped>
: Set rstInput = CurrentDb.OpenRecordset("YourInputTable")
: Set rstOutput = CurrentDb.OpenRecordset("YourOutputTable")
: rstInput .MoveFirst
: Do While Not rstInput .EOF
: lngProdCode = rstInput ("Prod_Code")
: strAttCode = rstInput ("Attr_Code")
'*******If you replace the for and if in the next lines by**********
Dim i as Integer
Do While Not isnull(rst...etc)
i = i+1
you won't need to know the count of possible options, so the code
would not need modification if your options expand
: for i = 3 to 14
: 'stop if you get to a null field, assuming once you get to a
: null, there are no more after that
: if isnull (rstInput.fields(i) ) then
: exit for
: end if
: rstOutput .AddNew
: rstOutput ("Prod_Code") = lngProdCode
: rstOutput ("Attr_Code") = strAttCode
: rstOutput ("Option_Code") = rstInput.fields(i)
: rstto.Update
: next i
' ******* Loop /\ replaces next i ********
: rstInput.MoveNext
: Loop
<snip end cleanup>
--thelma
On 28 Nov 2005 05:25:38 GMT, Thelma Lubkin <th****@alpha2.csd.uwm.edu>
wrote: John Welch <john(remove)welch@cal(remove)central.com> wrote:
<preliminaries snipped>
: Set rstInput = CurrentDb.OpenRecordset("YourInputTable") : Set rstOutput = CurrentDb.OpenRecordset("YourOutputTable")
: rstInput .MoveFirst
: Do While Not rstInput .EOF : lngProdCode = rstInput ("Prod_Code") : strAttCode = rstInput ("Attr_Code")
'*******If you replace the for and if in the next lines by**********
Dim i as Integer Do While Not isnull(rst...etc) i = i+1 you won't need to know the count of possible options, so the code would not need modification if your options expand
: for i = 3 to 14
: 'stop if you get to a null field, assuming once you get to a : null, there are no more after that : if isnull (rstInput.fields(i) ) then : exit for : end if
: rstOutput .AddNew : rstOutput ("Prod_Code") = lngProdCode : rstOutput ("Attr_Code") = strAttCode : rstOutput ("Option_Code") = rstInput.fields(i) : rstto.Update
s/b
rstOutput.Update
: next i ' ******* Loop /\ replaces next i ********
: rstInput.MoveNext
: Loop <snip end cleanup> --thelma
Something like
SELECT Prod_Code, ATTR_CODE as ATTRCODE, OPT1 as OPTCODE
FROM tblProds
WHERE OPT1 Is Not Null
UNION
SELECT Prod_Code, ATTR_CODE, OPT2
FROM tblProds
WHERE OPT2 Is Not Null
UNION
SELECT Prod_Code, ATTR_CODE, OPT3
FROM tblProds
WHERE OPT3 Is Not Null
UNION
SELECT Prod_Code, ATTR_CODE, OPT4
FROM tblProds
WHERE OPT4 Is Not Null
UNION
SELECT Prod_Code, ATTR_CODE, OPT5
FROM tblProds
WHERE OPT5 Is Not Null
ORDER BY Prod_Code, ATTRCODE, OPTCODE
--
Terry Kreft
"Ken Capriell" <kc**@NOSPAM.COM> wrote in message
news:97*******************@216.196.97.136... I know that subject probably did not adequately explain anything so here goes...
I have an access file that needs to be transposed from its current format to a new format so that I can then export as a flat file to be imported into a shopping cart. This file is to create a set of attributes/options for each product.
The file I have is in a pretty standard format:
Prod_Code | ATTR_CODE | OPT1 | OPT2 | OPT3 | OPT4 | OPT5 0037 | Color | RED | GREEN |YELLOW |BROWN | BLUE 0037 | Size | SMALL | MED | LARGE | |
The above represents the single product with code 0037. The intended result is just what one would assume. 2 selectable attributes, color and size and each with their sub options (5 possible colors and 3 possible sizes).
Ok, the problem is the flat file needs to be structured thusly:
Prod_Code | ATTRCODE | OPTCODE 0037 | Color |RED 0037 | Color |GREEN 0037 | Color |YELLOW 0037 | Color |BROWN 0037 | Color |BLUE 0037 | Size |SMALL 0037 | Size |MED 0037 | Size |LARGE
The software expects incoming data to be one line at a time like that.
So, I need to revamp the structure of this table to make a new line every time a value in one of the "OPTx" fields is encountered - copying over whatever values were found in Prod_Code and ATTR_CODE and with the new column OPTCODE to hold the values removed from the multiple OPTx columns. It should be noted that some product's attributes have up to 14 options so it goes all the way to OPT14.
What magical spell must I cast to get where I need to go? Thanks much.
Or maybe better
SELECT Prod_Code, ATTRCODE, OPTCODE
FROM
(
SELECT Prod_Code, ATTR_CODE as ATTRCODE, OPT1 as OPTCODE, 1 as OB
FROM tblProds
WHERE OPT1 Is Not Null
UNION
SELECT Prod_Code, ATTR_CODE, OPT2, 2 as OB
FROM tblProds
WHERE OPT2 Is Not Null
UNION
SELECT Prod_Code, ATTR_CODE, OPT3, 3 AS OB
FROM tblProds
WHERE OPT3 Is Not Null
UNION
SELECT Prod_Code, ATTR_CODE, OPT4, 4 AS OB
FROM tblProds
WHERE OPT4 Is Not Null
UNION
SELECT Prod_Code, ATTR_CODE, OPT5, 5 AS OB
FROM tblProds
WHERE OPT5 Is Not Null
)
ORDER BY Prod_Code, ATTRCODE, OB
--
Terry Kreft
"Terry Kreft" <te*********@mps.co.uk> wrote in message
news:uh********************@karoo.co.uk... Something like
SELECT Prod_Code, ATTR_CODE as ATTRCODE, OPT1 as OPTCODE FROM tblProds WHERE OPT1 Is Not Null UNION SELECT Prod_Code, ATTR_CODE, OPT2 FROM tblProds WHERE OPT2 Is Not Null UNION SELECT Prod_Code, ATTR_CODE, OPT3 FROM tblProds WHERE OPT3 Is Not Null UNION SELECT Prod_Code, ATTR_CODE, OPT4 FROM tblProds WHERE OPT4 Is Not Null UNION SELECT Prod_Code, ATTR_CODE, OPT5 FROM tblProds WHERE OPT5 Is Not Null ORDER BY Prod_Code, ATTRCODE, OPTCODE -- Terry Kreft "Ken Capriell" <kc**@NOSPAM.COM> wrote in message news:97*******************@216.196.97.136...I know that subject probably did not adequately explain anything so here goes...
I have an access file that needs to be transposed from its current format to a new format so that I can then export as a flat file to be imported into a shopping cart. This file is to create a set of attributes/options for each product.
The file I have is in a pretty standard format:
Prod_Code | ATTR_CODE | OPT1 | OPT2 | OPT3 | OPT4 | OPT5 0037 | Color | RED | GREEN |YELLOW |BROWN | BLUE 0037 | Size | SMALL | MED | LARGE | |
The above represents the single product with code 0037. The intended result is just what one would assume. 2 selectable attributes, color and size and each with their sub options (5 possible colors and 3 possible sizes).
Ok, the problem is the flat file needs to be structured thusly:
Prod_Code | ATTRCODE | OPTCODE 0037 | Color |RED 0037 | Color |GREEN 0037 | Color |YELLOW 0037 | Color |BROWN 0037 | Color |BLUE 0037 | Size |SMALL 0037 | Size |MED 0037 | Size |LARGE
The software expects incoming data to be one line at a time like that.
So, I need to revamp the structure of this table to make a new line every time a value in one of the "OPTx" fields is encountered - copying over whatever values were found in Prod_Code and ATTR_CODE and with the new column OPTCODE to hold the values removed from the multiple OPTx columns. It should be noted that some product's attributes have up to 14 options so it goes all the way to OPT14.
What magical spell must I cast to get where I need to go? Thanks much.
"Terry Kreft" <te*********@mps.co.uk> wrote in
news:cx********************@karoo.co.uk: Or maybe better
SELECT Prod_Code, ATTRCODE, OPTCODE FROM (
SELECT Prod_Code, ATTR_CODE as ATTRCODE, OPT1 as OPTCODE, 1 as OB FROM tblProds WHERE OPT1 Is Not Null UNION SELECT Prod_Code, ATTR_CODE, OPT2, 2 as OB FROM tblProds WHERE OPT2 Is Not Null UNION SELECT Prod_Code, ATTR_CODE, OPT3, 3 AS OB FROM tblProds WHERE OPT3 Is Not Null UNION SELECT Prod_Code, ATTR_CODE, OPT4, 4 AS OB FROM tblProds WHERE OPT4 Is Not Null UNION SELECT Prod_Code, ATTR_CODE, OPT5, 5 AS OB FROM tblProds WHERE OPT5 Is Not Null ) ORDER BY Prod_Code, ATTRCODE, OB
That's not legal Jet SQL. This would be:
SELECT Prod_Code, ATTRCODE, OPTCODE
FROM
[
SELECT Prod_Code, ATTR_CODE as ATTRCODE, OPT1 as OPTCODE, 1 as OB
FROM tblProds
WHERE OPT1 Is Not Null
UNION
SELECT Prod_Code, ATTR_CODE, OPT2, 2 as OB
FROM tblProds
WHERE OPT2 Is Not Null
UNION
SELECT Prod_Code, ATTR_CODE, OPT3, 3 AS OB
FROM tblProds
WHERE OPT3 Is Not Null
UNION
SELECT Prod_Code, ATTR_CODE, OPT4, 4 AS OB
FROM tblProds
WHERE OPT4 Is Not Null
UNION
SELECT Prod_Code, ATTR_CODE, OPT5, 5 AS OB
FROM tblProds
WHERE OPT5 Is Not Null
]. As Prods
ORDER BY Prod_Code, ATTRCODE, OB
--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Well, it works, so that's ok then.
--
Terry Kreft
"David W. Fenton" <dX********@bway.net.invalid> wrote in message
news:Xn**********************************@216.196. 97.142... "Terry Kreft" <te*********@mps.co.uk> wrote in news:cx********************@karoo.co.uk:
Or maybe better
SELECT Prod_Code, ATTRCODE, OPTCODE FROM (
SELECT Prod_Code, ATTR_CODE as ATTRCODE, OPT1 as OPTCODE, 1 as OB FROM tblProds WHERE OPT1 Is Not Null UNION SELECT Prod_Code, ATTR_CODE, OPT2, 2 as OB FROM tblProds WHERE OPT2 Is Not Null UNION SELECT Prod_Code, ATTR_CODE, OPT3, 3 AS OB FROM tblProds WHERE OPT3 Is Not Null UNION SELECT Prod_Code, ATTR_CODE, OPT4, 4 AS OB FROM tblProds WHERE OPT4 Is Not Null UNION SELECT Prod_Code, ATTR_CODE, OPT5, 5 AS OB FROM tblProds WHERE OPT5 Is Not Null ) ORDER BY Prod_Code, ATTRCODE, OB
That's not legal Jet SQL. This would be:
SELECT Prod_Code, ATTRCODE, OPTCODE FROM [
SELECT Prod_Code, ATTR_CODE as ATTRCODE, OPT1 as OPTCODE, 1 as OB FROM tblProds WHERE OPT1 Is Not Null UNION SELECT Prod_Code, ATTR_CODE, OPT2, 2 as OB FROM tblProds WHERE OPT2 Is Not Null UNION SELECT Prod_Code, ATTR_CODE, OPT3, 3 AS OB FROM tblProds WHERE OPT3 Is Not Null UNION SELECT Prod_Code, ATTR_CODE, OPT4, 4 AS OB FROM tblProds WHERE OPT4 Is Not Null UNION SELECT Prod_Code, ATTR_CODE, OPT5, 5 AS OB FROM tblProds WHERE OPT5 Is Not Null ]. As Prods ORDER BY Prod_Code, ATTRCODE, OB
-- David W. Fenton http://www.bway.net/~dfenton dfenton at bway dot net http://www.bway.net/~dfassoc
TTBOMK
() is fine for JET 4.0
and
[]. AS Whatever is required for JET 3.5 and OK for JET 4.0.
Well, something changed to allow (); so 4.0 is my story and I'm
sticking to it. What else could it be?
[]. AS Whatever has an advantage in that it can be used in 3.5 and 4.0.
() has an advantage in that it's similar to other dialects.
As I doubt that I will ever be required to write 3.5 again, I will
probably use () from now on. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: googlinggoogler |
last post by:
Hiya,
The title says it all really, but im a newbie to python sort of. I can
read in files and write files no probs.
But what I want to do is read in a couple of files and output them to
one...
|
by: Colleyville Alan |
last post by:
I am constructing a SQL command from a function. Some code builds the WHERE
clause in a looping structure and passes that as an argument to the
SQL-building function. But the results do not...
|
by: Ross A. Finlayson |
last post by:
Hi,
I'm scratching together an Access database. The development box is
Office 95, the deployment box Office 2003.
So anyways I am griping about forms and global variables. Say for
example...
|
by: scottyman |
last post by:
I can't make this script work properly. I've gone as far as I can with
it and the rest is out of my ability. I can do some html editing but
I'm lost in the Java world. The script at the bottom of...
|
by: HeEm |
last post by:
In my 100 level CS course, I was asked to create multiple lines of
output within a single string. Of course I know how to:
print "I am"
print "a python"
print "newbie."
How can I get this...
|
by: =?Utf-8?B?TG9zdEluTUQ=?= |
last post by:
Hi All :)
I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView.
True DBGrid has a MultipleLines property that controls whether individual
records span multiple lines. Is...
|
by: Peter Hartlén |
last post by:
I understand that the\n and \r only means something to the C# compiler so
when retrieving a line like "Hello\r\nWorld" from a resource file (localized
form or self made resource file), it prints...
|
by: tjm0713 |
last post by:
Not sure this can be done but here is my current situation. I have a table containing millions of records. Each record has 28 fields. One of the fields I am trying to return the single record for...
|
by: KevinADC |
last post by:
Note: You may skip to the end of the article if all you want is the perl code.
Introduction
Many websites have a form or a link you can use to download a file. You click a form button or click...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |