Execute statement in sp Urgent Help!!!

  • Hi,

    I have all column stored in @ tablecol variable in SP. Like 1st column is table name followed by field name. I want to pull Table name first and then want to insert other column in tables fetched. I used this statement. This will give me Table name but how to use in SP don't know. Here split is a function.

    Pls. suggests.

    select @Tname='select top 1 tablename  from split (''' + @Tablecol + ''','+ '''|'''+')'

    Thanks in Advance.

    Raju

  • A bit confusing.

    So you have a table variable called @tablecol that has two fields (table name and column name).

    What do you mean by "I want to pull Table name first and then want to insert other column in tables fetched"?

    And what does all of this have to do with the subject of "Execute Statement"??

    Maybe if you provide some more details and a small sample of what you want to do we'll be able to help.

     

    --------------------
    Colt 45 - the original point and click interface

  • 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

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply