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  | 
                             
                            
                                    | 
                                         charford 
                                        Starting Member 
                                         
                                        
                                        8 Posts  | 
                                        
                                        
                                            
                                            
                                             Posted - 2011-10-14 : 04:22:34
                                            
  | 
                                             
                                            
                                            | How can I use IF/BEGIN/END within the update statement?I'm, working on a stored procedure to update a table from another using UPDATE...FROMI need to check an incoming varchar value from my source table and convert it to a numerical value for the updatee.g.UPDATE dbo.Table2IF UD.code = 'S'  BEGIN  TagetVal = 20END  ELSEBEGIN  TargetVal = 0END FROM dbo.Table1 UDWHERE Table2.ID = Table1.ID | 
                                             
                                         
                                     | 
                             
       
                            
                       
                          
                            
                                    | 
                                     visakh16 
                                    Very Important crosS Applying yaK Herder 
                                     
                                    
                                    52326 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2011-10-14 : 04:36:36
                                          
  | 
                                         
                                        
                                          | [code]UPDATE t2SET t2.TagetVal = CASE WHEN UD.code = 'S' THEN 20 ELSE 0 ENDFROM dbo.Table2 t2JOIN dbo.Table1 UDON UD.ID = t2.ID[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     charford 
                                    Starting Member 
                                     
                                    
                                    8 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2011-10-14 : 05:08:22
                                          
  | 
                                         
                                        
                                          | Many thanks to visakh16UPDATE t2SET t2.TagetVal = CASE WHEN UD.code = 'S' THEN 20 ELSE 0 ENDFROM dbo.Table2 t2JOIN dbo.Table1 UDON UD.ID = t2.IDThis works perfectly for me.  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     visakh16 
                                    Very Important crosS Applying yaK Herder 
                                     
                                    
                                    52326 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2011-10-14 : 05:14:36
                                          
  | 
                                         
                                        
                                          | welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                            
                                | 
                                    
                                      
                                     
                                    
                                 | 
                             
                         
                     | 
                 
             
         |