我正在使用MSSQL Server 2008。 我正在尝试更新MySQL数据库。我使用MySQL-Database加入了MSSQL-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'
区别在于选择和更新,但它忽略了更新中的“位置”。
答案 0 :(得分: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'