1

我正在使用 MSSQL Server 2008。我正在尝试更新 MySQL 数据库。我将 MSSQL-Database 与 MySQL-Database 一起加入,现在尝试完成更新,但遇到了一个奇怪的问题。

当我执行以下查询时,我得到的结果数量有限:

select *
FROM [SQL-Database].[dbo].[Table] as c left join
openquery(MYSQL, 'select * from MySQL-Database.Table')
on c.KuNr=kunden_id collate German_PhoneBook_BIN
where c.Auswahltyp='2' and c.[gelöscht]=0 
                       and c.[Mietzeit bis]>GETDATE() and c.aktiveMail>'0'

当我进行更新时,它会更新数据库中的所有行:

update openquery(MYSQL, 'select * from MySQL-Database.Table')
set paket_id=7
FROM [SQL-Database].[dbo].[Table] as c left join
openquery(MYSQL, 'select * from MySQL-Database.Table')
on c.KuNr=kunden_id collate German_PhoneBook_BIN
where c.Auswahltyp='2' and c.[gelöscht]=0 
                       and c.[Mietzeit bis]>GETDATE() and c.aktiveMail>'0'

区别只是选择和更新,但它有点忽略了更新中的“位置”。

4

1 回答 1

0

为您的 openquery 命名,它应该可以工作,例如:

update k
set paket_id=7
FROM [SQL-Database].[dbo].[Table] as c left join
openquery(MYSQL, 'select * from MySQL-Database.Table') as k
on c.KuNr=k.kunden_id collate German_PhoneBook_BIN
where c.Auswahltyp='2' and c.[gelöscht]=0 
and c.[Mietzeit bis]>GETDATE() and c.aktiveMail>'0'
于 2012-08-17T16:50:14.870 回答