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  | 
                             
                            
                                    | 
                                         batcater98 
                                        Starting Member 
                                         
                                        
                                        22 Posts  | 
                                        
                                        
                                            
                                            
                                             Posted - 2014-07-15 : 12:12:54
                                            
  | 
                                             
                                            
                                            | Trying to update a field in an table with a sum from itself. Can't quite get the syntax down.. Here is what I have.. What am I missing.Update EventDataSet DivTotal = (Select EventKey, SUM(EventPoints) as DivTotal                From EventData                Where eventcode = 'F'                Group by Eventkey)I know I probably need to be doing an inner join of something to make this crude statment work, but brain not working today.Help Please.Ad.Regards,The Dark Knight-Give What is Right, Not What is Left- | 
                                             
                                         
                                     | 
                             
       
                            
                       
                          
                            
                                    | 
                                     tkizer 
                                    Almighty SQL Goddess 
                                     
                                    
                                    38200 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2014-07-15 : 12:46:12
                                          
  | 
                                         
                                        
                                          | Update EventDataSet DivTotal = (Select SUM(EventPoints) as DivTotalFrom EventDataWhere eventcode = 'F'Group by Eventkey)Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     batcater98 
                                    Starting Member 
                                     
                                    
                                    22 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2014-07-15 : 16:01:03
                                          
  | 
                                         
                                        
                                          | This gives me the same error I was getting.. You can't use an expression in the subquery.Error: 0x0 at Execute SQL Task: Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.Error: 0xC002F210 at Execute SQL Task, Execute SQL Task: Executing the query "Update EventDataRegards,The Dark Knight-Give What is Right, Not What is Left-  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     tkizer 
                                    Almighty SQL Goddess 
                                     
                                    
                                    38200 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2014-07-15 : 16:11:16
                                          
  | 
                                         
                                        
                                          | Sorry, try this:Update eSet DivTotal = t.DivTotalfrom EventData edjoin (Select EventKey, SUM(EventPoints) as DivTotalFrom EventDataWhere eventcode = 'F'Group by Eventkey) ton ed.EventKey = t.EventKeyTara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                            
                                | 
                                    
                                      
                                     
                                    
                                 | 
                             
                         
                     | 
                 
             
         |   
     
     
            
              
	     |  
		
			
     
          
		 |