Sql server 尝试根据条件从列复制值时发生SQL错误
错误:“update”处或附近的语法错误不确定是什么原因导致了错误,但您的最终Sql server 尝试根据条件从列复制值时发生SQL错误,sql-server,Sql Server,错误:“update”处或附近的语法错误不确定是什么原因导致了错误,但您的最终where子句似乎有误: with dummytable as ( Select table2.number, table2.paymentto from table2 inner join table1 on table1.number = table2.number and table2.number='1' and table2.paymentto is not null and
where
子句似乎有误:
with dummytable as
(
Select table2.number, table2.paymentto
from table2
inner join table1 on table1.number = table2.number and table2.number='1'
and table2.paymentto is not null and table2.paymentto !='B'
)
update table1
set ProvCOBAdjustments = (Select TotCOBAdjustmentAmt
from table1, dummytable
where dummytable.paymentto='P'and dummytable.number = table1.number)
where table1.paymentto is null;
不应该这样写吗
where table.paymentto is null
相反?此代码中没有语法错误。您在此处发布的内容之前或之后,可能存在与原始表名有关的内容或代码中的内容。我想您需要:
where table1.paymentto is null
否则,您将尝试执行某种相关子查询,而这一切都将非常顺利
此外,逗号式连接最近也很不受欢迎——我将其改写为:
update table1
set ProvCOBAdjustments = TotCOBAdjustmentAmt
from table1, dummytable
where dummytable.paymentto='P'and dummytable.number = table1.number
and table1.paymentto is null;
SQL Server的版本是什么 如果是SQL Server 2000或更早版本,则无法以当前形式运行此查询 此查询使用所谓的CTE公共表表达式(dummytable为(…)部分的
)。在SQLServer2005中引入了CTE支持
安装在我的somputer上的SQL Server 2008 R2不会抱怨此查询中的语法。抱歉,这只是一个输入错误…我用表1和表2替换了我的实际表名…我正在用我机器中的实际表名运行此查询,我得到了语法error@Ramya-您的表名没有空格/奇数字符/使用保留关键字,是吗?我看不出这个查询怎么会出现语法错误。
update t1
set
ProvCOBAdjustments = TotCOBAdjustmentAmt
from
table1 t1
inner join
dummytable dt
on
dt.number = t1.number
where
dt.paymentto='P' and
t1.paymentto is null;