简体   繁体   English

如何编写SQL查询以从ODBC源中选择行?

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

I'm fairly new to SQL, and MSSQL in particular. 我对SQL特别是MSSQL还是很陌生。 I'm looking for a way to select certain rows from an ODBC data source I have already set up into a table. 我正在寻找一种从已经设置到表中的ODBC数据源中选择某些行的方法。 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? 我上面有什么可能,还是我需要寻找其他解决方案?

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 如果是这样,您可能想研究使用链接服务器: http : //msdn.microsoft.com/zh-cn/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 如果只是一次或很少发生,那么您可以使用OPENROWSET并假设ODBC存在于服务器本身上: http : //msdn.microsoft.com/zh-cn/library/aa276850( v=sql.80) .aspx

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

Ok, but you want to pull certain ROWS into a new table. 好的,但是您想将某些ROWS放入新表中。 For that just add a WHERE clause: 为此,只需添加一个WHERE子句:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM