在SQL表中动态插入where子句

时间:2013-07-04 07:08:07

标签: sql insert where

我的表格COMPONENTS包含3列(SnoComponentQuantity),其中我正在撰写Sno和{{1}最初的列,我想使用某个表达式(例如Component)来填充“数量”列,其中包含来自另一个表 ((d1+d2)*d3) 的变量。

这里我需要根据COMPONENTS表(components.sno)中的Sno列中的值将值写入数量列。

我曾经在'x'中保留表达式值并尝试插入COMPONENTS,如下所示:

SHEET(d1 int,d2 int ,d3 int,d4 int ,d5 int,d6 int)

但上述查询显示insert into components(Quantity) values(x) where components.sno='y'; [Y is inetger starting from 0 to 70]

处的错误

请建议我最好的SQL查询来实现这一目标! 在此先感谢..!

2 个答案:

答案 0 :(得分:7)

除非是INSERT,否则您无法WHERE WHERE NOT EXISTS子句,所以只需执行:

INSERT INTO components(Quantity) VALUES(x)

也许你需要做UPDATE

UPDATE components SET Quantity=x WHERE components.sno='y';

答案 1 :(得分:-1)

IF之前使用insert声明,不要使用where条款:

If <your condition>
  Begin <your statement>
End