Home Forums SQL Server 7,2000 T-SQL Execute statement in sp Urgent Help!!! RE: Execute statement in sp Urgent Help!!!

  • Hi Phill,

    Thanks for prompt reply... Actually Pls. find the the whole procedure... In which i am 1st import a text file. Then i have to Fetch the Table name from this file along with Column. And then insert into DB. Pls. find the whole procedure... for uor refrence

    Create PROC Sp_EnterTextFile @filename sysname   

    as    

    BEGIN    

       SET nocount ON    

       declare @Tablecol varchar(2550), @Tablename varchar(8000), @othercolumn varchar(2400), @statement varchar(400),@statement1 varchar(2400), @rowlen varchar(200) 

       

       CREATE TABLE #tempf (line varchar(8000))    

       EXEC ('bulk INSERT #tempf FROM "' + @filename + '"')    

     DECLARE pcursor CURSOR FOR   

      SELECT * FROM #tempf   

       

     OPEN pcursor   

       

     FETCH NEXT FROM pcursor into @Tablecol   

        

     WHILE @@FETCH_STATUS = 0   

      BEGIN    

       select @statement='select * from split (''' + @Tablecol + ''','+ '''|'''+')'  

        

       FETCH NEXT FROM pcursor into @Tablecol   

      END   

       

       CLOSE pcursor   

       DEALLOCATE pcursor   

        

       DROP TABLE #tempf    

    END    

     

    Here The statement in red will give me all data along with Table name. But i don't know how to use that in procedure. Using Exec (@statement), I could able to check the thing. But could not able to use.

    Thanks

    Raju