How can I insert the result of stored sp_tables_ex  into Table Temp

Posted on 2006-05-09
Last Modified: 2008-01-09
I have a linked server called NW. The linked sever is used to access data from  Northwind.mdb I used exec sp_tables_ex 'NW' command to get table informations of Northwind.mdb . How can I get the result of the stored sp_tables_ex 'NW'  into table temp?Please help me
Question by:jujin
    LVL 17

    Accepted Solution

    Suppose you have created a temp table

    insert into #tmp exec sp_tables_ex 'NW'
    LVL 4

    Assisted Solution

    The INSERT command supports calling a stored procedure to supply rows for insertion into a table.

    CREATE TABLE #locks (spid int, dbid int, objid int, objectname sysname NULL,
     indid int, type char(4), resource char(15), mode char(10), status char(6))
    INSERT #locks (spid, dbid, objid, indid, type, resource, mode, status)
    EXEC dbo.sp_lock
    SELECT * FROM #locks
    DROP TABLE #locks

    This is a handy way of trapping the output of a stored procedure in a table so that you can manipulate it or retain it for later use. Prior to the advent of cursor OUTPUT parameters, this was the only way to perform further work on a stored procedure's result set within Transact-SQL.

    INSERT...EXEC works with extended procedures that return result sets as well.

    CREATE TABLE #cmd_result (output varchar(8000))
    INSERT #cmd_result
    EXEC master.dbo.xp_cmdshell 'TYPE C:\BOOT.INI'
    SELECT * FROM #cmd_result
    DROP TABLE #cmd_result

    Hope that will answer your query.

    Chetan Sachdeva

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Introduction If you are not already aware of what you could use a table with sequential integer values for in SQL, you can read Delimited String Parsing in SQL Server 2005 or later ( by BrandonGalderisi (h…
    I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now