?
Solved

Show the detail data of what I have grouped in SQL2005

Posted on 2014-09-18
4
Medium Priority
?
137 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 49

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 2000 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

764 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