【发布时间】:2023-03-23 09:47:01
【问题描述】:
我必须使用 MySQL 数据库中的数据在 SQL Server 中运行查询。当我需要做相反的事情时,我找到了一种简单的方法来完成我需要使用 SQL Server 中的 select 语句编写更新查询。
我在 SQL Server 中写道:
SELECT 'update sgidb.Example set MySQLCol1 = ' + cast(MSSQLCol1 as varchar(max)) + ' where MySQLCol2 = ' + cast(MSSQLCol2 as varchar(max)) + ';' FROM MSSQLTable
这导致了一堆带有我需要的键的更新语句:
'update sgidb.Example set MySQLCol1 = 12 where MySQLCol2 = 45;
但是当我尝试在 MySQL 中做同样的事情时,我遇到了一堆语法错误。网络告诉我 MySQL 不需要 + 运算符来连接句子中的字符串,但它不起作用,也没有显式地编写连接函数。有什么想法吗?
【问题讨论】:
-
使用concat会发生什么
-
无法使 concat(cast(MSSQLCol1 as varchar(max)), 'etctera') 工作
-
好吧,也许发布该代码并出现错误 - 因为“无法正常工作”并不能告诉我们出了什么问题。
-
在 SQL Server 中也可以进行 CONCAT 函数。
SELECT CONCAT('update sgidb.Example set MySQLCol1 = ' , MSSQLCol1 , ' where MySQLCol2 = ' , MSSQLCol2 , ';' )FROM MSSQLTable
标签: mysql sql-server database