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  | 
                             
                            
                                    | 
                                         KPS 
                                        Starting Member 
                                         
                                        
                                        2 Posts  | 
                                        
                                        
                                            
                                            
                                             Posted - 2012-04-30 : 04:07:33
                                            
  | 
                                             
                                            
                                            | Sir,I want to insert data from one database to another on the same server through stored procedure.I am trying to execute the following Stored Procedure code in SQL Server 2000Declare @DB nvarchar(20)Set @DB = 'ADMMGS001'Execute ('Use ' + @DB + '; Insert Into Stud_Personal_Detail (lSPD_IdNo,sStud_Name) Values(1,A)')But i get the following error. Please Help....Its Urgent!!The name 'A' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted. | 
                                             
                                         
                                     | 
                             
       
                            
                       
                          
                            
                                    | 
                                     jimf 
                                    Master Smack Fu Yak Hacker 
                                     
                                    
                                    2875 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2012-04-30 : 08:39:12
                                          
  | 
                                         
                                        
                                          | Try thisDeclare @DB nvarchar(20)Set @DB = 'ADMMGS001'PRINT ('Insert Into ['+@db+'].dbo.Stud_Personal_Detail (lSPD_IdNo,sStud_Name) Values(1,''A'')')Note that I also included the object owner (dbo) and added single quotes around AJimEveryday I learn something that somebody else already knew  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     visakh16 
                                    Very Important crosS Applying yaK Herder 
                                     
                                    
                                    52326 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2012-04-30 : 10:26:16
                                          
  | 
                                         
                                        
                                          | why do you need dynamic sql for that? why is dbname determined dynamically?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                            
                                | 
                                    
                                      
                                     
                                    
                                 | 
                             
                         
                     | 
                 
             
         |