| Author | 
                                
                                 Topic  | 
                             
                            
                                    | 
                                         man889 
                                        Starting Member 
                                         
                                        
                                        25 Posts  | 
                                        
                                        
                                            
                                            
                                             Posted - 2011-04-16 : 22:03:17
                                            
  | 
                                             
                                            
                                            | SELECT Sum(JobItem.JobPrice) AS JobPrice_Type_1_Sum, JobItem.InvNoFROM JobItemWHERE (((JobItem.JobTypeId)=1))GROUP BY JobItem.InvNo;SELECT Sum(JobItem.JobPrice) AS JobPrice_Type_2_Sum, JobItem.InvNoFROM JobItemWHERE (((JobItem.JobTypeId)=2))GROUP BY JobItem.InvNo;SELECT Sum(JobItem.JobPrice) AS JobPrice_Type_3_Sum, JobItem.InvNoFROM JobItemWHERE (((JobItem.JobTypeId)=3))GROUP BY JobItem.InvNo;SELECT Sum(JobItem.JobPrice) AS JobPrice_Type_4_Sum, JobItem.InvNoFROM JobItemWHERE (((JobItem.JobTypeId)=4))GROUP BY JobItem.InvNo; | 
                                             
                                         
                                     | 
                             
       
                            
                       
                          
                            
                                    | 
                                     man889 
                                    Starting Member 
                                     
                                    
                                    25 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2011-04-16 : 22:26:18
                                          
  | 
                                         
                                        
                                          | Can I combine it into one table by InvNo andhaving the column of InvNo, JobPrice_Type_1_Sum, JobPrice_Type_2_Sum, JobPrice_Type_3_Sum, JobPrice_Type_4_Sum  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     AndrewMurphy 
                                    Master Smack Fu Yak Hacker 
                                     
                                    
                                    2916 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2011-04-18 : 05:10:02
                                          
  | 
                                         
                                        
                                          | Have a look at the CASE statementselect invno,  case when JobTypeId = 1 then JobPrice  else 0  end as job1_raw,  case when JobTypeId = 2 then JobPrice  else 0  end as job2_raw,  etcfrom jobitemwrap the results inside a "group by" clause.  Have a go, experiment and revert here with any problems.  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     man889 
                                    Starting Member 
                                     
                                    
                                    25 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2011-04-18 : 05:40:20
                                          
  | 
                                         
                                        
                                          | Hi AndrewMurphy,Thank for your reply.I figure out what I am look for is transform pivot after spend several hours searching.and now I can get the result from ms accessTRANSFORM Sum(JobItem.JobPrice) AS JobPriceOfSumSELECT JobItem.InvNo, Sum(JobItem.JobPrice) AS [Total Of JobPrice]FROM JobItemGROUP BY JobItem.InvNoPIVOT JobItem.JobTypeId;Here is the table and sample dataJobId, JobItemNo, InvNo, JobTypeId, JobPrice1, 1, 3401, 1, 502, 2, 3403, 1, 603, 3, 3401, 2, 5604, 4, 3402, 3, 105, 5, 3401, 1, 1706, 1, 3402, 4, 1407, 2, 3402, 3, 1408, 1, 3403, 1, 3009, 1, 3404, 2, 30010, 1, 3405, 1, 30011, 1, 3406, 1, 34012, 1, 3407, 1, 30013, 1, 3408, 1, 300InvNo, Total Of JobPrice, JobTypeId 1, JobTypeId 2, JobTypeId 3, JobTypeId43418, 1090, 1080, 0, 10, 03419, 300, 300, 0, 0, 03420, 350, 300, 0, 0, 503421, 736 , 736 , 0, 0, 03422, 300, 300, 0, 0, 03429, 3400, 1150, 2250, 0, 03430, 2200, 0, 0, 2200, 03431, 2200, 0, 2200, 0, 03432, 2500, 0, 2500, 0, 03433, 1950, 0, 1950, 0, 0but Now I am facing another problem is actually I will run the sql in VB.NET, the problem is VB.NET not allow using Transform pivot.How can I convert it into standard sql statement?Thank  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     AndrewMurphy 
                                    Master Smack Fu Yak Hacker 
                                     
                                    
                                    2916 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2011-04-18 : 07:22:17
                                          
  | 
                                         
                                        
                                          | I'm not familiar with vb.net, but the SQL I provided "is standard" and will point you in the right direction.  Have a go and post your efforts for others to observe and fine-tune.  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     SMerrill 
                                    Posting Yak  Master 
                                     
                                    
                                    206 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2011-04-29 : 19:10:29
                                          
  | 
                                         
                                        
                                          | Are you using ADO.NET to connect with Access?~ Shaun MerrillSeattle area  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     nigelrivett 
                                    Master Smack Fu Yak Hacker 
                                     
                                    
                                    3385 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2011-04-29 : 19:27:38
                                          
  | 
                                         
                                        
                                          | SELECT JobItem.InvNo,Sum(case when JobItem.JobTypeId)=1 then JobItem.JobPrice else 0 end) AS JobPrice_Type_1_Sum, Sum(case when JobItem.JobTypeId)=2 then JobItem.JobPrice else 0 end) AS JobPrice_Type_2_Sum, ...FROM JobItemGROUP BY JobItem.InvNo;I think in access it might be something likeSELECT JobItem.InvNo,Sum(iif (JobItem.JobTypeId)=1 , JobItem.JobPrice , 0) ) AS JobPrice_Type_1_Sum, Sum(iif ( JobItem.JobTypeId)=2, JobItem.JobPrice, 0) ) AS JobPrice_Type_2_Sum, ...FROM JobItemGROUP BY JobItem.InvNo;==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy.  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                            
                                | 
                                    
                                      
                                     
                                    
                                 | 
                             
                         
                     | 
                 
             
         |