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.

 All Forums
 Other Forums
 Other Topics
 insert into openquery

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-05-23 : 09:00:36
Lucia writes "I need to access from MSSQL to a Sybase database. I have used openquery in order to perform a select but I cannot find any example of how to use openquery as the target of an INSERT. The manual says you can do it but does not explain how. Basically I need to select from a couple of tables in my MSSQL database and insert it into a simple table in my Sybase database. I have defined the linked server and can connect to the database but do not know how to write the INSERT command."

jasper_smith
SQL Server MVP & SQLTeam MVY

846 Posts

Posted - 2002-05-23 : 18:15:19
INSERT
OPENQUERY(TEST,'select log_text,log_date from bcaidba.dbo.xml_cat_log')
SELECT 'This is a test insert',getdate()

In the OPENQUERY statement you need to write a SELECT statement naming the columns in the table you want to insert into (in my example these are log_text and log_date) and then use a normal select statement to select the rows from your tables as per usual.

Basicaly the select in the OPENQUERY takes the place of the INSERT
statements target column list

HTH
Jasper Smith


Go to Top of Page

eBlazer
Starting Member

1 Post

Posted - 2009-09-17 : 11:34:58
Thanks Jasper - You saved me a lot of time and effort!
Go to Top of Page
   

- Advertisement -