Solved

Convert summary list to detail list SQL MS Access

Posted on 2011-03-08
10
282 Views
Last Modified: 2012-06-22
I am looking for an efficient way to turn:

SKU   priceshed  R1 R5   W1 W5 W10 W25 W50
1099  branch       $5         $3         2.99
1089   branch      $1  .99  .75               .69
where R1 is the retail price for 1 item, W1 is the wholsale price for 1item
And turn it into

SKU  priceshed   Rate           From      To               Price
1099  Branch     Retail             1        9999              $5
1099  Branch     Wholesale     1            9                $3
1099  Branch     Wholesale     10      9999              $2.99  
1089  Branch      Retail            1          4                  $1
1089  Branch      Retail            5        9999              $3
1089  Branch     Wholesale     1         24                 $.75
1089  Branch     Wholesale      25     9999              $.69


There will always be an R1 and W1 with any combination of the rest.
9999 is the max number on the "to" count.

Right now I am using multiple queries to accomplish this. I would like to create a VB script to do the work.  Once this conversion is complete the converted table is in the same format as the production system pricing guide and then we compare the two and make changes.  The origin format is to make it easy on the person who has to update pricing on many items relatively often.

Any ideas would be greatly appreciated.

thanks
0
Comment
Question by:chenault68
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 35071690
>>Zones: Microsoft Access Database, Databases Miscellaneous, MS SQL Server<<
If you are looking for a T-SQL solution, the way you would do this is with the UNION ALL clause, in other words build a series of SQL statements with a UNION ALL in between.

If on the other hand, this question is not using T-SQL than I suggest you request that the MS SQL Server zone be removed.
0
 

Author Comment

by:chenault68
ID: 35071999
You are correct  I should have added VB in the place of SQL.
0
 
LVL 8

Expert Comment

by:Andrew_Webster
ID: 35072062
Can you show us a bit more sample data from the first set, maybe even put it into an Excel sheet or something to show us how it's arranged in a table?
0
 
LVL 3

Expert Comment

by:AccessYourBiz_Com
ID: 35074215
You should use the InStr function to parse through the each line of data. Looks like the beginning of each line starts with "SKU". Then also use the Mid() function to step through each part of the string and extract the information you want and put into the table.
I can try to put something together which may help.
0
 
LVL 3

Expert Comment

by:AccessYourBiz_Com
ID: 35074328
What determines the SKU 1099 vs 1089 in your string "SKU   priceshed  R1 R5   W1 W5 W10 W25 W50"?

The detail of your second line reads:
1099  Branch     Wholesale     1            9                $3

I understand the Price of $1 is from W1, but where are you getting the $3 price from? I don't see anything in the string for that. Same question for the "9".

Basically you need to use the Instr() function and/or the Mid() function to parse through your string and add the records. If the length of the string is fixed, then you only need to use the Mid() function since you can determine the fixed starting and ending lengths of the data you want to extract.
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 3

Accepted Solution

by:
AccessYourBiz_Com earned 500 total points
ID: 35084153
I actually created a seperate query to provide the totals and brought that into your query. See attached.
Branch-Tables-Test-by-Scott-Webe.zip
0
 

Author Closing Comment

by:chenault68
ID: 35084333
Thanks for the help
0
 
LVL 3

Expert Comment

by:AccessYourBiz_Com
ID: 35085321
your welcome. I actually posted that last file to the wrong thread. I am assuming you were able to find solution with the InStr() and Mid() functions.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 35086283
>>your welcome. I actually posted that last file to the wrong thread<<
That is too funny!
0
 
LVL 3

Expert Comment

by:AccessYourBiz_Com
ID: 35086521
glad I could bring some amusement to your life ac! ;-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now