tsql - "Incorrect syntax near 'WHERE'" in Delete queries
问题描述
For about the past year I having an issue with having my delete queries recognize a where clause. I am not talking about big major complex queries. Even little simple queries.
Usually I am in a hurry so rather than try to analyze the issue I simply utilize a join on a subquery to specify which rows to delete. But now I want to know what's going on. I've looked other places on stackoverflow but those errors were always due to something obvious like a extra comma, or trying to use the where clause with an Insert values statement.
The culprit today is the following:
DELETE FROM prc_ContractChanges chgs
WHERE chgs.ChangeTypeID = 1
Similar constructs have worked fine for the last 19 years. So why all of a sudden does this throw the obscene error
Incorrect syntax near 'WHERE'.
I tried to add a comment in response to one below but each attempt end with "an error occurred when adding this comment" so UI am editing the original question
That suggestion below worked. So it occurred to me how would you identify the multiple tables in a delete with a join. So I put the alias in the delete clause. That worked. It occurred to me that putting the alias in the delete clause with a single table delete would work as well. It did.
解决方案
You can use one of the following syntaxes:
DELETE prc_ContractChanges
FROM prc_ContractChanges chgs
WHERE chgs.ChangeTypeID = 1
DELETE prc_ContractChanges
WHERE ChangeTypeID = 1
推荐阅读
- javascript - 是否有官方或库函数来验证 React Native 中状态和 GPS 权限的变化?
- python - 如何优化这个 Tensorflow 加权平均自定义操作
- r - 如何一次运行多个线性模型
- javascript - URL/字符串的正则表达式 - 如果协议返回 false
- notepad++ - 无论单词中字母的大小如何,如何使用所有变体来引用单词?
- svg - 对于独立的 SVG(.svg 文件),是否必须包含 DOCTYPE 和 XML 声明?
- makefile - Make:函数中特定于目标的变量赋值
- performance - 尽管响应时间在设定的持续时间内显着变化,但所有 API 的吞吐量都是恒定的
- python - python pandas:lambda或其他计算NaN值/ len(value)<1沿行的方法
- java - 如何实现“在资源管理器/查找器中定位”功能