| 
                
Please start any new threads on our new 
    site at https://forums.sqlteam.com.  We've got lots of great SQL Server
    experts to answer whatever question you can come up with. 
    
        | 
                
                    | 
                            
                                | Author | Topic |  
                                    | CON78788Starting Member
 
 
                                        1 Post | 
                                            
                                            |  Posted - 2010-02-20 : 03:29:53 
 |  
                                            | Dear All,In my tblQuery1, I have the following data:IsoLbl               Comp2        StencilPBBCA-PR-16223.01    ELBOW        GK14PBBCA-PR-16223.01    ELBOW        GK24PBBCA-PR-16223.01    ELBOW        GK50PBBCA-PR-16223.01    ELBOW        GK55PBBCA-PR-16223.01    FLANGE       GK27PBBCA-PR-16223.01    FLANGE       GK28In the IsoLbl field as you can see there are 6 identical data. Under the Comp2 field there are 2 types of Iso Components which is the Elbow and the Flange. On the last field there are 4 different Stencils; GK14, GK24, GK50 & GK55. I want these 4 Stencils to be combined in one field since they fall under the same component of ELBOW....so forth and so on.Report output should look like this:IsoLbl               Comp2        StencilPBBCA-PR-16223.01    ELBOW        GK14,GK24,GK50,GK55PBBCA-PR-16223.01    FLANGE       GK27,GK28I tried using the Grouping but no success.Your help is highly appreciated. Thanks.CON78788 |  |  
                                    | vaibhavktiwari83Aged Yak Warrior
 
 
                                    843 Posts | 
                                        
                                          |  Posted - 2010-02-20 : 05:30:31 
 |  
                                          | This might be your solution -----DECLARE @temp TABLE ( IsoLbl VARCHAR(100), Comp2 VARCHAR(20), Stencil VARCHAR(20) )INSERT INTO @temp SELECT 'PBBCA-PR-16223.01', 'ELBOW', 'GK14'UNION ALLSELECT 'PBBCA-PR-16223.01', 'ELBOW', 'GK24'UNION ALLSELECT 'PBBCA-PR-16223.01', 'ELBOW', 'GK50'UNION ALLSELECT 'PBBCA-PR-16223.01', 'ELBOW', 'GK55'UNION ALLSELECT 'PBBCA-PR-16223.01', 'FLANGE', 'GK27'UNION ALLSELECT 'PBBCA-PR-16223.01', 'FLANGE', 'GK28'DECLARE @ROWCOUNT BIGINTDECLARE @Stencil VARCHAR(MAX)  DECLARE @C VARCHAR(20) DECLARE @Iso VARCHAR(100)DECLARE @TAB TABLE (IsoLbl VARCHAR(100), Comp2 VARCHAR(20))DECLARE @TAB1 TABLE (IsoLbl VARCHAR(100), Comp2 VARCHAR(20),Stencil VARCHAR(MAX))INSERT INTO @TABSELECT DISTINCT IsoLbl , Comp2FROM @tempSET @ROWCOUNT = @@ROWCOUNTWHILE @ROWCOUNT>0BEGINSET @Stencil = ''SELECT TOP 1 @Iso=IsoLbl, @C=Comp2 FROM @TAB ORDER BY Comp2SELECT @Stencil =@Stencil+',' + Stencil     FROM  (				SELECT Stencil FROM @Temp				WHERE Comp2 = @c               ) X			INSERT INTO @TAB1 (isolbl,comp2,stencil) VALUES(@iso,@C,SUBSTRING(@Stencil ,2,LEN(@Stencil )) )                      DELETE  A FROM @TAB A                      INNER JOIN @TAB1 B  ON  B.Comp2=A.Comp2           SET @ROWCOUNT =@ROWCOUNT-@@ROWCOUNT         END       SELECT  * FROM @TAB1 WHERE Stencil <>''-------Refer your main table tblQuery1 instead of @temp table Vabhav T |  
                                          |  |  |  
                                    | madhivananPremature Yak Congratulator
 
 
                                    22864 Posts | 
                                        
                                          |  Posted - 2010-02-20 : 05:47:59 
 |  
                                          | quote:The question is posted at MS Access forum in which your solution will not workMadhivananFailing to plan is Planning to failOriginally posted by vaibhavktiwari83
 This might be your solution -----DECLARE @temp TABLE ( IsoLbl VARCHAR(100), Comp2 VARCHAR(20), Stencil VARCHAR(20) )INSERT INTO @temp SELECT 'PBBCA-PR-16223.01', 'ELBOW', 'GK14'UNION ALLSELECT 'PBBCA-PR-16223.01', 'ELBOW', 'GK24'UNION ALLSELECT 'PBBCA-PR-16223.01', 'ELBOW', 'GK50'UNION ALLSELECT 'PBBCA-PR-16223.01', 'ELBOW', 'GK55'UNION ALLSELECT 'PBBCA-PR-16223.01', 'FLANGE', 'GK27'UNION ALLSELECT 'PBBCA-PR-16223.01', 'FLANGE', 'GK28'DECLARE @ROWCOUNT BIGINTDECLARE @Stencil VARCHAR(MAX)  DECLARE @C VARCHAR(20) DECLARE @Iso VARCHAR(100)DECLARE @TAB TABLE (IsoLbl VARCHAR(100), Comp2 VARCHAR(20))DECLARE @TAB1 TABLE (IsoLbl VARCHAR(100), Comp2 VARCHAR(20),Stencil VARCHAR(MAX))INSERT INTO @TABSELECT DISTINCT IsoLbl , Comp2FROM @tempSET @ROWCOUNT = @@ROWCOUNTWHILE @ROWCOUNT>0BEGINSET @Stencil = ''SELECT TOP 1 @Iso=IsoLbl, @C=Comp2 FROM @TAB ORDER BY Comp2SELECT @Stencil =@Stencil+',' + Stencil     FROM  (				SELECT Stencil FROM @Temp				WHERE Comp2 = @c               ) X			INSERT INTO @TAB1 (isolbl,comp2,stencil) VALUES(@iso,@C,SUBSTRING(@Stencil ,2,LEN(@Stencil )) )                      DELETE  A FROM @TAB A                      INNER JOIN @TAB1 B  ON  B.Comp2=A.Comp2           SET @ROWCOUNT =@ROWCOUNT-@@ROWCOUNT         END       SELECT  * FROM @TAB1 WHERE Stencil <>''-------Refer your main table tblQuery1 instead of @temp table Vabhav T
 
 |  
                                          |  |  |  
                                    | vaibhavktiwari83Aged Yak Warrior
 
 
                                    843 Posts | 
                                        
                                          |  Posted - 2010-02-20 : 06:37:29 
 |  
                                          | Oh really i missed sorry i cant help in ms accessbut if you can convert it then well and goodVabhav T |  
                                          |  |  |  
                                |  |  |  |  |  |