SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 EXEC sp_table
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

funk.phenomena
Posting Yak Master

Canada
120 Posts

Posted - 08/09/2013 :  11:06:20  Show Profile  Reply with Quote
Hi All - I'm using the following syntax to extract a list of all the table names on a linked server:

EXEC sp_tables_ex
@table_server = MY_SERVER_NAME


It outputs a list of tables into 4 columns in the result window.

Is there a way an can use this as a 'SELECT * FROM ... " command so that I can organize records, insert into, etc etc ?

Thanks!

James K
Flowing Fount of Yak Knowledge

3323 Posts

Posted - 08/09/2013 :  11:09:48  Show Profile  Reply with Quote
quote:
Originally posted by funk.phenomena

Hi All - I'm using the following syntax to extract a list of all the table names on a linked server:

EXEC sp_tables_ex
@table_server = MY_SERVER_NAME


It outputs a list of tables into 4 columns in the result window.

Is there a way an can use this as a 'SELECT * FROM ... " command so that I can organize records, insert into, etc etc ?

Thanks!

Create a table with those four columns. Then use the INSERT..EXEC syntax like this:
INSERT INTO YourNewTable
EXEC sp_tables_ex
@table_server = MY_SERVER_NAME
Then you can select and sort and filter from that table.
Go to Top of Page

funk.phenomena
Posting Yak Master

Canada
120 Posts

Posted - 09/09/2013 :  13:36:33  Show Profile  Reply with Quote
Thanks James!
Is there a more automated way of building a table based on a SP like this (like a SELECT * INTO) ?
Some of the tables have many columns, and it's very tedious to manually create tables and specify the data types for each column.
Go to Top of Page

TG
Flowing Fount of Yak Knowledge

USA
5907 Posts

Posted - 09/09/2013 :  13:54:04  Show Profile  Reply with Quote
There is a way to do it although wouldn't recommend it for a production environment. You could set up a linked server that points to itself (loopback). Then do this:
select * into #tb from openquery(<loopbackLinkedServer>, 'exec mySP')

EDIT:
I've used this technique in dev just to get a table created then generate a create script from that table to use where needed. You just need to scrutinize the resulting datatypes and sizes to make sure they will work for all data that could be returned that and not just the data was returned for that particular call.

Be One with the Optimizer
TG

Edited by - TG on 09/09/2013 13:59:26
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000