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 |  
                                    | sri189Starting Member
 
 
                                        4 Posts | 
                                            
                                            |  Posted - 2010-07-23 : 06:21:05 
 |  
                                            | Hi,I have to write an update stmt where i have to loop through the rows of a temptable and if the id exists i have to do the update pls help me on how to go abt thisthanks in advancesri |  |  
                                    | madhivananPremature Yak Congratulator
 
 
                                    22864 Posts | 
                                        
                                          |  Posted - 2010-07-23 : 06:24:13 
 |  
                                          | update temptableset col='some value'where <some condition>MadhivananFailing to plan is Planning to fail |  
                                          |  |  |  
                                    | sri189Starting Member
 
 
                                    4 Posts | 
                                        
                                          |  Posted - 2010-07-23 : 10:32:19 
 |  
                                          | how to loop thro' the table? and thn write the updatesri |  
                                          |  |  |  
                                    | pk_bohraMaster Smack Fu Yak Hacker
 
 
                                    1182 Posts | 
                                        
                                          |  Posted - 2010-07-23 : 11:39:13 
 |  
                                          | Can you provide table structure of the table that is source of data and the table that needs to be updated.If possible, provide some sample data too. |  
                                          |  |  |  
                                    | sri189Starting Member
 
 
                                    4 Posts | 
                                        
                                          |  Posted - 2010-07-26 : 05:20:20 
 |  
                                          | can some one help me with the below update stmt.. id doesnt seem to work!!UPDATE Table1 SET SALES_USER_NAME = MO.SALES_USER_NAME, ROLENAME = MO.ROLENAME from #temptable MO1,(SELECT MO1.SALES_USER_NAME, MO1.ROLENAME FROM #temptable MO1 JOIN table1 ON#temptable.OPPORTUNITY_ID = table1.OPPORTUNITY_ID)MO WHERE MO.OPPORTUNITY_ID = table1.OPPORTUNITY_IDsri |  
                                          |  |  |  
                                    | khtanIn (Som, Ni, Yak)
 
 
                                    17689 Posts | 
                                        
                                          |  Posted - 2010-07-26 : 05:29:36 
 |  
                                          | Can you explain more on "doesn't seem to work!!" ? ?The query gives you error ? It does not execute as what you have expected ?Post some sample data and show us the expected result. KH[spoiler]Time is always against us[/spoiler]
 |  
                                          |  |  |  
                                    | oxeggStarting Member
 
 
                                    6 Posts | 
                                        
                                          |  Posted - 2010-07-30 : 03:24:15 
 |  
                                          | You can try to replace #temptable with tempdb..#temptable |  
                                          |  |  |  
                                |  |  |  |