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 |
funk.phenomena
Posting Yak Master
121 Posts |
Posted - 2013-08-09 : 11:06:20
|
Hi All - I'm using the following syntax to extract a list of all the table names on a linked server:[CODE]EXEC sp_tables_ex@table_server = MY_SERVER_NAME[/CODE]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
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-08-09 : 11:09:48
|
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:[CODE]EXEC sp_tables_ex@table_server = MY_SERVER_NAME[/CODE]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 YourNewTableEXEC sp_tables_ex@table_server = MY_SERVER_NAME Then you can select and sort and filter from that table. |
|
|
funk.phenomena
Posting Yak Master
121 Posts |
Posted - 2013-09-09 : 13:36:33
|
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. |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2013-09-09 : 13:54:04
|
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 OptimizerTG |
|
|
|
|
|