473,473 Members | 2,044 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

query to split fields into multiple rows?

bu
I have a database field that represents an item description and varying
length. I am using the database to import the item description into another
program (the other program is ODBC-aware ). The problem is that the
description would be imported into the other program in lengths of 50
characters. So if the entire description is 160 chars, the program would
need the description in 4 rows - 3 rows of 50 and 1 row of 10.

I have been trying to determine a way to write a query that would
essentially parse the description field into lengths of 50 chars AND return
each parsed chunk as a different row. Needless to say, I am stumped.

If anyone has any ideas or suggestions, it would be greatly appreciated!

thanks in advance,
bill
Nov 13 '05 #1
5 6082
bu wrote:
I have a database field that represents an item description and varying
length. I am using the database to import the item description into another
program (the other program is ODBC-aware ). The problem is that the
description would be imported into the other program in lengths of 50
characters. So if the entire description is 160 chars, the program would
need the description in 4 rows - 3 rows of 50 and 1 row of 10.

I have been trying to determine a way to write a query that would
essentially parse the description field into lengths of 50 chars AND return
each parsed chunk as a different row. Needless to say, I am stumped.

If anyone has any ideas or suggestions, it would be greatly appreciated!

thanks in advance,
bill


Hmmm...of the top of my head...

Write a function that uses the InsertInto SQL command. In this
function, you'd pass the string to be split and any "key" info. Here's
some air code

Public Sub SplitIT(strToSplit As String)
Dim intLoop As Integer
Dim strHold As String
strInsert As String

strToSplit = Trim(strToSpit)

intLoop = 50
Do while intLoop - 49 >= len(strToSplit)
strHold = Mid(strToSplit,intLoop -49,50)
'get the 50 chars and insert into the export table
strInsert = "Insert into ExportTable " & _
"(Field) Values ('" & strHold & "')"
Currentdb.Execute strInsert
intLoop = intLoop + 50
Loop
End Sub
I'd have a table that I'd export to your other program. Then run a query
to clear out all existing records in the export table. Then open a
recordset for the records you'll be exporting. Then loop thru the
recordset and pass the description field (and any others to insert into
export) and insert those records to the export file.
Nov 13 '05 #2
Execute a series of Append query statements, reading 50-char at a time.
For example, the source for the 2nd one would be:
SELECT Mid([Descrip], 51, 50)
FROM Table1
WHERE Len([Descrip]) > 50

If this is extended, or needs to be done repeatedly, you could write some
VBA code that loops through appending each 50 char at a time, until there
are no more records returned, i.e. until db.RecordsAffected = 0.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"bu" <bu@nospam.com> wrote in message
news:8j*****************@fe07.lga...
I have a database field that represents an item description and varying
length. I am using the database to import the item description into
another
program (the other program is ODBC-aware ). The problem is that the
description would be imported into the other program in lengths of 50
characters. So if the entire description is 160 chars, the program would
need the description in 4 rows - 3 rows of 50 and 1 row of 10.

I have been trying to determine a way to write a query that would
essentially parse the description field into lengths of 50 chars AND
return
each parsed chunk as a different row. Needless to say, I am stumped.

If anyone has any ideas or suggestions, it would be greatly appreciated!

thanks in advance,
bill

Nov 13 '05 #3
bu
I think I like this solution... I'll give it a whirl!

Thanks!
"Salad" <oi*@vinegar.com> wrote in message
news:hG*****************@newsread1.news.pas.earthl ink.net...
bu wrote:
I have a database field that represents an item description and varying
length. I am using the database to import the item description into another program (the other program is ODBC-aware ). The problem is that the
description would be imported into the other program in lengths of 50
characters. So if the entire description is 160 chars, the program would need the description in 4 rows - 3 rows of 50 and 1 row of 10.

I have been trying to determine a way to write a query that would
essentially parse the description field into lengths of 50 chars AND return each parsed chunk as a different row. Needless to say, I am stumped.

If anyone has any ideas or suggestions, it would be greatly appreciated!

thanks in advance,
bill


Hmmm...of the top of my head...

Write a function that uses the InsertInto SQL command. In this
function, you'd pass the string to be split and any "key" info. Here's
some air code

Public Sub SplitIT(strToSplit As String)
Dim intLoop As Integer
Dim strHold As String
strInsert As String

strToSplit = Trim(strToSpit)

intLoop = 50
Do while intLoop - 49 >= len(strToSplit)
strHold = Mid(strToSplit,intLoop -49,50)
'get the 50 chars and insert into the export table
strInsert = "Insert into ExportTable " & _
"(Field) Values ('" & strHold & "')"
Currentdb.Execute strInsert
intLoop = intLoop + 50
Loop
End Sub
I'd have a table that I'd export to your other program. Then run a query
to clear out all existing records in the export table. Then open a
recordset for the records you'll be exporting. Then loop thru the
recordset and pass the description field (and any others to insert into
export) and insert those records to the export file.

Nov 13 '05 #4
bu
This is also a good idea.... thanks for the help!
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:41***********************@per-qv1-newsreader-01.iinet.net.au...
Execute a series of Append query statements, reading 50-char at a time.
For example, the source for the 2nd one would be:
SELECT Mid([Descrip], 51, 50)
FROM Table1
WHERE Len([Descrip]) > 50

If this is extended, or needs to be done repeatedly, you could write some
VBA code that loops through appending each 50 char at a time, until there
are no more records returned, i.e. until db.RecordsAffected = 0.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"bu" <bu@nospam.com> wrote in message
news:8j*****************@fe07.lga...
I have a database field that represents an item description and varying
length. I am using the database to import the item description into
another
program (the other program is ODBC-aware ). The problem is that the
description would be imported into the other program in lengths of 50
characters. So if the entire description is 160 chars, the program would need the description in 4 rows - 3 rows of 50 and 1 row of 10.

I have been trying to determine a way to write a query that would
essentially parse the description field into lengths of 50 chars AND
return
each parsed chunk as a different row. Needless to say, I am stumped.

If anyone has any ideas or suggestions, it would be greatly appreciated!

thanks in advance,
bill


Nov 13 '05 #5
bu wrote:
This is also a good idea.... thanks for the help!
I vote for Allen's solution. Very easy to implement.


"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:41***********************@per-qv1-newsreader-01.iinet.net.au...
Execute a series of Append query statements, reading 50-char at a time.
For example, the source for the 2nd one would be:
SELECT Mid([Descrip], 51, 50)
FROM Table1
WHERE Len([Descrip]) > 50

If this is extended, or needs to be done repeatedly, you could write some
VBA code that loops through appending each 50 char at a time, until there
are no more records returned, i.e. until db.RecordsAffected = 0.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"bu" <bu@nospam.com> wrote in message
news:8j*****************@fe07.lga...
I have a database field that represents an item description and varying
length. I am using the database to import the item description into
another
program (the other program is ODBC-aware ). The problem is that the
description would be imported into the other program in lengths of 50
characters. So if the entire description is 160 chars, the program
would
need the description in 4 rows - 3 rows of 50 and 1 row of 10.

I have been trying to determine a way to write a query that would
essentially parse the description field into lengths of 50 chars AND
return
each parsed chunk as a different row. Needless to say, I am stumped.

If anyone has any ideas or suggestions, it would be greatly appreciated!

thanks in advance,
bill



Nov 13 '05 #6

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

Similar topics

5
by: johkar | last post by:
This script works fine if all form fields have one value, but what do you do if one of the form fields was a multiple select? Example: status=blue&status=red function getParams() { var...
9
by: Ed_No_Spam_Please_Weber | last post by:
Hello All & Thanks in advance for your help! Background: 1) tblT_Documents is the primary parent transaction table that has 10 fields and about 250,000 rows 2) There are 9 child tables with...
2
by: Justin Koivisto | last post by:
I am attempting to execute a *long* query string via a ADODB.Recordset.Open (queryStr) call. Most of the time, the query string will be less than 100 characters, but in some cases, it may be up to...
1
by: Robert | last post by:
I am trying to create a db for service providers by county. I'm relatively new to db programming, but I have done quite a bit of programming ranging from the old basic days up to doing some...
2
by: Smartin | last post by:
Using Access 97 I am trying to create a form that allows for user entry of search terms and displays a table of results. I thought I could accomplish this using a subform but it isn't quite...
6
by: MVM | last post by:
Hi, I am attempting to run a query in MS SQL server between two tables that have a one to many relationship. The tables are linked on GID. What I want is one instance of every record from Table...
2
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
How can I run this query against a table in my Access database? I don't know hwo to use it in C#. In VB I would use .Recordset = "some sql statement". How do I do this in C#? //I get a vlaue...
2
by: jennk | last post by:
i am working in Access 97, our database tables are linked from ODBCsqlsvr (not even sure what that means). i have a table where each record has a unique customer and their order information. there...
1
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...
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
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,...
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.