DeveloperBarn Forums

Go Back   DeveloperBarn Forums > Databases > Microsoft Access

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 « Previous Thread | Next Thread »
 
LinkBack Thread Tools Display Modes
  #11 (permalink)  
Old May 2nd, 2008, 08:09 AM
AOG123's Avatar
Lightning Master

 
Join Date: Mar 2008
Location: Fortress Of Solitude
Posts: 76
Thanks: 6
Thanked 20 Times in 15 Posts
Rep Power: 1
AOG123 is on a distinguished road

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, 9 views)
__________________
If i helped you, make me famous by clicking the
Sponsored Links
  #12 (permalink)  
Old May 2nd, 2008, 08:27 AM
jmurrayhead's Avatar
Your Lord & Master

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 537
Thanks: 14
Thanked 40 Times in 39 Posts
Blog Entries: 2
Rep Power: 1
jmurrayhead will become famous soon enough

Awards Showcase
Microsoft .Net Microsoft SQL Server Microsoft Windows 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
Did I help you out? Make me popular by clicking the icon!

If you found a post helpful, please click the button in the lower right-hand corner of the post.

Powered by ASP.Net
  #13 (permalink)  
Old May 2nd, 2008, 10:37 AM
AOG123's Avatar
Lightning Master

 
Join Date: Mar 2008
Location: Fortress Of Solitude
Posts: 76
Thanks: 6
Thanked 20 Times in 15 Posts
Rep Power: 1
AOG123 is on a distinguished road

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 (permalink)  
Old May 2nd, 2008, 11:25 AM
AOG123's Avatar
Lightning Master

 
Join Date: Mar 2008
Location: Fortress Of Solitude
Posts: 76
Thanks: 6
Thanked 20 Times in 15 Posts
Rep Power: 1
AOG123 is on a distinguished road

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 (permalink)  
Old May 2nd, 2008, 12:57 PM
jmurrayhead's Avatar
Your Lord & Master

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 537
Thanks: 14
Thanked 40 Times in 39 Posts
Blog Entries: 2
Rep Power: 1
jmurrayhead will become famous soon enough

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

Default

How are you trying to call this function?
  #16 (permalink)  
Old May 2nd, 2008, 01:30 PM
AOG123's Avatar
Lightning Master

 
Join Date: Mar 2008
Location: Fortress Of Solitude
Posts: 76
Thanks: 6
Thanked 20 Times in 15 Posts
Rep Power: 1
AOG123 is on a distinguished road

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 (permalink)  
Old May 2nd, 2008, 01:31 PM
jmurrayhead's Avatar
Your Lord & Master

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 537
Thanks: 14
Thanked 40 Times in 39 Posts
Blog Entries: 2
Rep Power: 1
jmurrayhead will become famous soon enough

Awards Showcase
Microsoft .Net Microsoft SQL Server Microsoft Windows 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 (permalink)  
Old May 2nd, 2008, 01:38 PM
AOG123's Avatar
Lightning Master

 
Join Date: Mar 2008
Location: Fortress Of Solitude
Posts: 76
Thanks: 6
Thanked 20 Times in 15 Posts
Rep Power: 1
AOG123 is on a distinguished road

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 (permalink)  
Old May 2nd, 2008, 01:46 PM
jmurrayhead's Avatar
Your Lord & Master

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 537
Thanks: 14
Thanked 40 Times in 39 Posts
Blog Entries: 2
Rep Power: 1
jmurrayhead will become famous soon enough

Awards Showcase
Microsoft .Net Microsoft SQL Server Microsoft Windows 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 (permalink)  
Old May 2nd, 2008, 08:13 PM
don94403's Avatar
Moderator


 
Join Date: Mar 2008
Location: San Mateo, CA, USA
Posts: 44
Thanks: 2
Thanked 4 Times in 4 Posts
Blog Entries: 2
Rep Power: 1
don94403 is on a distinguished road

Awards Showcase
PHP Microsoft Access 
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


Sponsored Links

ASP.NET Resource Index
a directory of ASP.NET tutorials, applications, scripts, assemblies and articles for the novice to professional developer.

Free Web Directory
Including Chats and Forums Resources, Offer automatic, instant and free directory submissions.
URLZ Web Directory
URLZ Web Directory

Free Web Directory - Add Your Link
The Little Web Directory
Free Web Directory
Pegasus free web directory is a free directory organised by categories.

Web Directory & SEO Services
dirroot web directory


All times are GMT -4. The time now is 09:23 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
Copyright © 2008 DeveloperBarn.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46