需要帮助在 Informix 上运行此 MS SQL Server 语句
我需要帮助在 Informix(版本 11)上运行此 MS SQL Server UPDATE 语句:
update b
set Colname = 'StringValue'
from Table1 b right join Table1 c
on ((b.Col1 = c.Col1) and (b.Col2 = c.Col2))
where ((b.Col3 = 'S' and b.Col4 <> 'S') and (c.Col3 = 'Z' and c.Col4 <> 'S'))
我不断收到错误号 -201(语法错误)。
你能看到任何语法错误吗?有什么想法吗?
I need help running this MS SQL Server UPDATE statement on Informix (version 11):
update b
set Colname = 'StringValue'
from Table1 b right join Table1 c
on ((b.Col1 = c.Col1) and (b.Col2 = c.Col2))
where ((b.Col3 = 'S' and b.Col4 <> 'S') and (c.Col3 = 'Z' and c.Col4 <> 'S'))
I keep getting error number -201 (syntax error).
Can you see any syntax error? Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用的是哪个版本的 Informix?
实际上,我认为这并不重要...IDS 不支持 UPDATE 语句,即使在最新版本中也是如此。所以,问题是您正在尝试使用 DBMS 不支持的符号,因此您会得到恼人的(但在本例中是准确的)通用“-201:发生语法错误”。我认为即使是最新的 GA 版本 IDS 11.70.xC1 也不支持 UPDATE 语句中的表别名(这使查询变得复杂)。
我承认 RIGHT {self} JOIN 让我感到困惑 - 我不确定我是否理解它应该如何工作。然而,这里是对所请求的更新的一个适度的近似:
令人烦恼的疑问有两个方面:
不幸的是,当查询运行时,我得到了答案:
有一些解决方法,使用临时表,但它们很麻烦。然而,这个示例代码似乎按照我的预期工作(鉴于我仍然无法理解 RIGHT JOIN 在原始代码中所做的事情)。
片段“
{Table1 AS}
”是 Informix 中的注释。由于临时表 C 的创建方式,Col3 和 Col4 上的条件并不是严格必需的。我在 UPDATE 语句之前和之后从 SELECT * FROM Table1 ORDER BY Col1, Col2, Col3, Col4 得到的结果是:
Which version of Informix are you using?
Actually, I don't think it matters...IDS does not support join notations in the UPDATE statement, even in the latest version. So, the problem is you are trying to use a notation that is not supported by the DBMS, and hence you get back the annoying (but, in this case, accurate) generic "-201: A syntax error has occurred". I don't think even IDS 11.70.xC1, the latest GA version, supports table aliases in the UPDATE statement, either (which complicates the query).
I confess that the RIGHT {self} JOIN has me bemused - I'm not sure I understand how it should work. However, here is a moderate approximation to the requested update:
The nagging doubts are two-fold:
Unfortunately, when the query is run, I get back:
There are workarounds for that, using temporary tables, but they're a nuisance. However, this example code seems to work according to my expectations (given that I still can't wrap my brain around what the RIGHT JOIN is doing in the original).
The fragment '
{Table1 AS}
' is a comment in Informix. The conditions on Col3 and Col4 are not strictly necessary because of the way that temp table C is created.The results I get from
SELECT * FROM Table1 ORDER BY Col1, Col2, Col3, Col4
before and after the UPDATE statement are: