Register Blogs FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

Go Back   DeveloperBarn Forums > Databases > Microsoft Access

Sponsored Links

Discuss "Slow Concat Code" in the Microsoft Access forum.

Microsoft Access - Microsoft Access is a database for small to medium applications. Learn tips and tricks and best database practices here.


Closed Thread
 
LinkBack Thread Tools Display Modes
  #11  
Old May 2nd, 2008, 08:09 AM
AOG123's Avatar
Lightning Master
 
Join Date: Mar 2008
Location: Fortress Of Solitude
Posts: 107
Thanks: 10
Thanked 27 Times in 21 Posts
Rep Power: 1
AOG123 will become famous soon enough

Awards Showcase
Microsoft Access 
Total Awards: 1

Default

Hi,.. again,...

have a look at this attachment,.. its fast very fast even accross the network,.. but at the moment its creating a table,.. i must use this in a query as the data must be real time,

Anyone have any ideas on how to convert this to be called direct in a query?
Attached Files
File Type: zip Consolidate1.zip (22.2 KB, 10 views)
__________________
If i helped you, make me famous by clicking the
Sponsored Links
  #12  
Old May 2nd, 2008, 08:27 AM
jmurrayhead's Avatar
The Barnfather
 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 941
Thanks: 22
Thanked 93 Times in 90 Posts
Blog Entries: 5
Rep Power: 4
jmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the rough

Awards Showcase
Microsoft Windows Microsoft SQL Server Microsoft .Net Classic ASP 
Total Awards: 4

Default

A temp table is a very good idea. I should have suggested it yesterday, but I didn't think of it at the time.

Anyway, I can't think of anyway of calling that routine within the actual query. Why do you want to? What are you trying to achieve by calling it directly from the query?

I'm also thinking this could be simplified if more tables were used with some relationships instead of using comma delimited fields. However, I'm so used to the power of SQL Server and the powerful queries that can be used there, I'm not sure if it would work the same with Access.
__________________
jmurrayhead
If you agree with me... click the icon!
If my post solved your problem, click the button in the lower right-hand corner of the post.

If you like it here...throw us a few bones to help
support us.

Join our Folding team: DeveloperBarn Folding

  #13  
Old May 2nd, 2008, 10:37 AM
AOG123's Avatar
Lightning Master
 
Join Date: Mar 2008
Location: Fortress Of Solitude
Posts: 107
Thanks: 10
Thanked 27 Times in 21 Posts
Rep Power: 1
AOG123 will become famous soon enough

Awards Showcase
Microsoft Access 
Total Awards: 1

Default

To explain more,.. this is what i have and works fine,..."except having to wait a minute for the concat

When a job is created item required to be purchased are put in the Requests Table

Code:
Tbl_03_Requests
ID #	Part Number	Description	            Status	Qty Req	UOM	Priority	Req #	Work Order
1	114N4082-6	Leading Edge Skin	Stock Required	1	ea	Priority 1		WO07-421
Often the same part is Required on a different job,.

Code:
Tbl_03_Requests
ID #	Part Number	Description	            Status	Qty Req	UOM	Priority	Req #	Work Order
50	114N4082-6	Leading Edge Skin	Stock Required	1	ea	Priority 1		WO07-690
A query then creates a list to purchase

Code:
ID #	Part Number	Description	            Status	Qty Req	UOM	Work Order
1-50	114N4082-6	Leading Edge Skin	Stock Required	2	ea	WO07-421 - WO07-690
The ID is then purchased against on the Order Screen

The Id goes into the purchase order table

The Id is then Split back down to its original numbers

The original numbers then look back at the Request table and update the status to Ordered

Code:
Tbl_03_Requests
ID #	Part Number	Description	        Status	Qty Req	UOM	Priority	Req #	Work Order
1	114N4082-6	Leading Edge Skin	Ordered	1	ea	Priority 1		WO07-421

Code:
Tbl_03_Requests
ID #	Part Number	Description	        Status	Qty Req	UOM	Priority	Req #	Work Order
50	114N4082-6	Leading Edge Skin	Ordered	1	ea	Priority 1		WO07-690
And so on,. When the unit is received it changes the status to received.

Sorry about the Table Formatting,... Can anyone think of another way to do this?
  #14  
Old May 2nd, 2008, 11:25 AM
AOG123's Avatar
Lightning Master
 
Join Date: Mar 2008
Location: Fortress Of Solitude
Posts: 107
Thanks: 10
Thanked 27 Times in 21 Posts
Rep Power: 1
AOG123 will become famous soon enough

Awards Showcase
Microsoft Access 
Total Awards: 1

Default

Found another example,.. but can get it to work,...

error undefined function,...

Can someone try this using my first sample,... thanks

Code:
Public Function fConcatenateRecords(strField As String, strRecordset As String, strFieldSeparator As String) As String
'USAGE:
'       fContatenateRecords(FieldName to concatenate, Table; Query; or SQL SELECT recordset, Separator character)
   Dim curDB As DAO.Database
   Dim rst As DAO.Recordset
   Dim strTemp As String

   Set curDB = CurrentDb
   Set rst = curDB.OpenRecordset(strRecordset)
       With rst
           If .EOF And .BOF Then
           fConcatenateRecords = "" 'no records returned
           Exit Function
       End If

       .MoveFirst
       While Not .EOF
           strTemp = strTemp & .Fields(strField) & strFieldSeparator & " "
           .MoveNext
       Wend
       .Close
   End With

   strTemp = Left(strTemp, Len(strTemp) - (Len(strFieldSeparator) + 1))
   fConcatenateRecords = strTemp

End Function
  #15  
Old May 2nd, 2008, 12:57 PM
jmurrayhead's Avatar
The Barnfather
 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 941
Thanks: 22
Thanked 93 Times in 90 Posts
Blog Entries: 5
Rep Power: 4
jmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the rough

Awards Showcase
Microsoft Windows Microsoft SQL Server Microsoft .Net Classic ASP 
Total Awards: 4

Default

How are you trying to call this function?
  #16  
Old May 2nd, 2008, 01:30 PM
AOG123's Avatar
Lightning Master
 
Join Date: Mar 2008
Location: Fortress Of Solitude
Posts: 107
Thanks: 10
Thanked 27 Times in 21 Posts
Rep Power: 1
AOG123 will become famous soon enough

Awards Showcase
Microsoft Access 
Total Awards: 1

Default

fContatenateRecords("Table", "fieldName", "Separator character")

fContatenateRecords("FieldName", "Table", "Separator character")

I didn't write it so not sure if it even works
  #17  
Old May 2nd, 2008, 01:31 PM
jmurrayhead's Avatar
The Barnfather
 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 941
Thanks: 22
Thanked 93 Times in 90 Posts
Blog Entries: 5
Rep Power: 4
jmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the rough

Awards Showcase
Microsoft Windows Microsoft SQL Server Microsoft .Net Classic ASP 
Total Awards: 4

Default

Quote:
Originally Posted by AOG123 View Post
fContatenateRecords("Table", "fieldName", "Separator character")

fContatenateRecords("FieldName", "Table", "Separator character")

I didn't write it so not sure if it even works
Where are you calling it from? The test form?
  #18  
Old May 2nd, 2008, 01:38 PM
AOG123's Avatar
Lightning Master
 
Join Date: Mar 2008
Location: Fortress Of Solitude
Posts: 107
Thanks: 10
Thanked 27 Times in 21 Posts
Rep Power: 1
AOG123 will become famous soon enough

Awards Showcase
Microsoft Access 
Total Awards: 1

Default

just in the query,. i guess it should work like the other example,.. but maybe not,....
  #19  
Old May 2nd, 2008, 01:46 PM
jmurrayhead's Avatar
The Barnfather
 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 941
Thanks: 22
Thanked 93 Times in 90 Posts
Blog Entries: 5
Rep Power: 4
jmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the rough

Awards Showcase
Microsoft Windows Microsoft SQL Server Microsoft .Net Classic ASP 
Total Awards: 4

Default

Quote:
Originally Posted by AOG123 View Post
just in the query,. i guess it should work like the other example,.. but maybe not,....
Paste what you have here
  #20  
Old May 2nd, 2008, 08:13 PM
don94403's Avatar
Moderator
 
Join Date: Mar 2008
Location: San Mateo, CA, USA
Posts: 69
Thanks: 3
Thanked 12 Times in 10 Posts
Blog Entries: 7
Rep Power: 1
don94403 will become famous soon enough

Awards Showcase
Microsoft Access PHP 
Total Awards: 2

Default

I posted my contribution on "the other" forum but will duplicate it here, for the convenience of those who are already here and interested in your problem.

As I said over there, in my opinion, the issue is your schema. It doesn't meet 3NF normalization criteria. The reason that your approach is so slow is that you are calling a user-defined function 3 times in your SQL, and each time it is called, it has to read every record in the database, thus if you have 1,000 records, it will have to read 3 * 1,000 * 1,000, or 3 million records. It gets worse if you have even more records.

I normalized your data into 5 tables and now you don't need any functions or VBA code, just simple queries will do all the work. Access queries are pretty efficient and get optimized by Jet, so you should always let Jet do as much of the job as you can. You paid MS for Jet, so make it pay you back!

BTW, this was an interesting exercise for me.

Comments on this post
lewy agrees: Excellent job Don
jmurrayhead agrees: As I said earlier, a better design would make this more simple. Nice work, Don
sbenj69 agrees: great work Don
richyrich agrees: Nice Work Don...
Attached Files
File Type: zip powo.zip (27.7 KB, 5 views)
The Following User Says Thank You to don94403 For This Useful Post:
sbenj69 (May 27th, 2008)
Closed Thread

  DeveloperBarn Forums > Databases > Microsoft Access

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -4. The time now is 11:10 PM.



Content Relevant URLs by vBSEO 3.2.0