简体   繁体   中英

MSSQL to MYSQL - Select from MSSQL , Insert into MySQL

Im trying to Establish a One Direction Sync from a specific query'd recordset from MSSQL (express 2008) to Mysql. Here is that query.

SELECT [datafk]
  ,[datahistorypk]
  ,[date]
  ,[displayText]
FROM [FCentral].[dbo].[DataHistory]

WHERE [sampleNr] = 
    (SELECT MAX (sampleNr) FROM [FCentral].[dbo].[DataHistory])

This results in a Multiple results. I need to insert each of those results into my "Linked Server" remotely connected MySQL DB Table.

This code works from SSMS and does insert into my MySQL DB.

EXEC (' INSERT INTO  `farms`.`CCData` (
       `datafk` ,`datahistorypk` ,`date` ,`displayText` )
      VALUES ("222",  "13",  "2017-10-19 14:25:05",  "TEST"); ')
at BPF_REMOTE

Ultimately i will need to schedule this query to run automatically, It would be nice if it could run if a change was detected in the MSSQL table but that may be outside of my abilities.

I feel like im close, im just struggling to get the syntax right to convert from MSSQL to MySQL. Can anyone either point to a good example or help me with this query?

Set up a linked server in SQL Server and just do a regular insert:

INSERT INTO BPF_REMOTE.farms.CCData(datafk, datahistorypk, date, displayText)
    SELECT [datafk], [datahistorypk], [date], [displayText]
    FROM [FCentral].[dbo].[DataHistory]
    WHERE [sampleNr] = (SELECT MAX (sampleNr) FROM [FCentral].[dbo].[DataHistory]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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