[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.3

Query is splitting records, but that's not what i want...

Asked by bingie in Microsoft Access Database, SQL Query Syntax

I have my main table, named tblMain. Here is a sample data set from that table:

pk        itemID                stockID      status      
608      24538784      3833      -      
609      24538784      3881      remain      
610      24538784      5673      -      
633      24538784      4605      +      
634      24538784      105      +      
617      24540467      105      remain      
618      24540467      3881      remain      
619      24540467      5673      -      
624      24704802      866      remain      
625      24704802      5327      remain      
626      24704802      5673      -      
636      24704802      105      +      

I would like to "pivot" (almost...) this data so it's grouped by itemID with the status pre-pending the stockID. I am also ignoring the entries with status = "remain"

This is the output i get from my query now:

itemID           stockID    stockID2    stockID3      stockID4  stockID5      stockID6
24538784      - 3833      - 3881      - 5673                  
24538784      + 4605      +105                        
24540467      - 5673                              
24704802      - 5673                              
24704802      +105      

As you can see, it is seperating and grouping the entries if they contain " - " or " + ". I want them in the same record. Thus, I would like the output from the query to be:

itemID           stockID    stockID2    stockID3      stockID4  stockID5      stockID6
24538784      - 3833      - 3881      - 5673     + 4605      + 105                              
24540467      - 5673                              
24704802      - 5673      + 105                              

Here is my query. How can i change this to achieve my required format?

SELECT x.itemID, status+First(x.stockID1) AS stockID1, status+First(x.stockID2) AS stockID2, status+First(x.stockID3) AS stockID3, status+First(x.stockID4) AS stockID4, status+First(x.stockID5) AS stockID5, status+First(x.stockID6) AS stockID6
FROM [SELECT status,a.itemID, a.stockID AS stockID1,
(Select First(b.stockID) from tblMain b where b.itemID=a.itemID and b.PK = a.PK +1) AS stockID2,
(Select First(c.stockID) from tblMain c where c.itemID=a.itemID and c.Pk = a.PK +2) AS stockID3,
(Select First(d.stockID) from tblMain d where d.itemID=a.itemID and d.Pk = a.PK +3) AS stockID4,
(Select First(e.stockID) from tblMain e where e.itemID=a.itemID and e.Pk = a.PK +4) AS stockID5,
(Select First(f.stockID) from tblMain f where f.itemID=a.itemID and f.Pk = a.PK +5) AS stockID6
FROM tblMain AS a]. AS x
WHERE status<> 'remain'
GROUP BY x.itemID, status;

Many thanks
                        
[+][-]10/04/09 02:29 PM, ID: 25491074Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Microsoft Access Database, SQL Query Syntax
Sign Up Now!
Solution Provided By: matthewspatrick
Participating Experts: 1
Solution Grade: A
 
[+][-]10/04/09 05:44 PM, ID: 25491694Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89 - Hierarchy / EE_QW_3_20080625