Solved

Show the detail data of what I have grouped in SQL2005

Posted on 2014-09-18
4
135 Views
Last Modified: 2014-09-18
I am selecting a number of rows from SQL database within a Crystal report using an SQL command
I have a product field - 20 long  

I want to group my report by the first 4 characters of the Product - I do this by
CAST (rtrim(LTRIM(substring(product_ID,1,4))) AS char) as item_grouping,

This then reports all records that have the same first 4 characters.

In a seperate field I would like to see all the products that I have selected by there full product ID


example

File of data is like the following
ProductID, QTy
B3AA001            10
B3AA001            12
B3AA001            4
B3AA002            6
B3AA003            5
B3AB001            3
B3AB002            5
B3AB003            7
B3AB004            6



Report should look like
B3AA      37    (B3AA001, B3AA002 , B3AA003)

B3AB      21        (B3AB001, B3AB002 , B3AB003, B3AB004)
0
Comment
Question by:MECR123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40330057
you want this in TSQL (SQL Server) or to be done in Crystal?

if TSQL please provide the existing query.
0
 
LVL 8

Accepted Solution

by:
Ganapathi earned 500 total points
ID: 40330073
Try this.
Select SUBSTRING(ProductID,1,4) as Product,Count(1) as TotalQuantity
STUFF((SELECT ',' + ProductID FROM mytable WHERE (
ProductID=Result.ProductID) FOR XML PATH ('')),1,1,'') AS list
From mytable AS ProductIDAll
GROUP BY SUBSTRING(ProductID,1,4)

Open in new window

0
 

Author Comment

by:MECR123
ID: 40330260
hi Ganapathi

thanks

I think this will do the job
the only bit I can't understand is ProductID=Result.ProductID
in the sub Select for each record read I only want to select records that meet my substring criteria
0
 

Author Closing Comment

by:MECR123
ID: 40330301
excellent answer
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based developeā€¦
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundrā€¦

733 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