set @SQLQuery = 'update top (200) ' +@tablename+ 
  ' set Flag1 = ''new'' where [Flag1] = '+@flag1+'';
            Asked
            
        
        
            Active
            
        
            Viewed 683 times
        
    0
            
            
         
    
    
        Gordon Linoff
        
- 1,242,037
- 58
- 646
- 786
 
    
    
        Jay
        
- 1
- 
                    Got solution: exec('update top(200)'+@tablename+' set Flag1 = '''+@flag1+''' where Flag1 = ''new'''); – Jay Apr 09 '16 at 22:33
- 
                    As a good practice do not construct your query from parameters, since it will induce [SQL Injection](https://en.wikipedia.org/wiki/SQL_injection) – Apr 10 '16 at 09:41
- 
                    Thanks for your advice, @yildizm85. I'll keep in mind for my future implementations as well. – Jay Apr 10 '16 at 19:23
1 Answers
0
            
            
        You can try something like this.
set @SQLQuery = 'update ' +@tablename+ ' set Flag1 = ''new'' where [Flag1] = '+@flag1+' AND Flag1 IN (SELET TOP 200 Flag1 FROM ' +@tablename+ 'WHERE [Flag1] = '+@flag1+')';
 
    
    
        slnit
        
- 35
- 6
- 
                    Thanks a lot for your suggestions, here is my solution. exec('update top(200)'+@tablename+' set Flag1 = '''+@flag1+''' where Flag1 = ''new'''); – Jay Apr 09 '16 at 22:30