user1415799
user1415799

Reputation: 23

How do I write a SQL query to select rows from an ODBC source?

I'm fairly new to SQL, and MSSQL in particular. I'm looking for a way to select certain rows from an ODBC data source I have already set up into a table. Something along the lines of:

SELECT 
<somecolumns>
INTO
<target_table>
FROM
[ODBC_data_source].sourcetable 

I should also mention that the data source is properly configured, and I can import from it with the Import Wizard. Is what I have above possible, or do I need to look for other solutions?

Upvotes: 2

Views: 16335

Answers (2)

Levi W
Levi W

Reputation: 815

Are you going to be accessing this data source a lot? If so, you might want to look into using a linked server: http://msdn.microsoft.com/en-us/library/ms188279.aspx

If it's just a one time or very infrequent thing then you can use OPENROWSET assuming the ODBC exists on the server itself: http://msdn.microsoft.com/en-us/library/aa276850(v=sql.80).aspx

Upvotes: 2

Kris Gruttemeyer
Kris Gruttemeyer

Reputation: 872

SELECT column1, column2
INTO new_table_name [IN externaldatabase]
FROM old_tablename

Ok, but you want to pull certain ROWS into a new table. For that just add a WHERE clause:

SELECT column1, column2
INTO new_table_name [IN externaldatabase]
FROM old_tablename
WHERE Name in('Mark','Luke',etc)

Upvotes: 0

Related Questions