SELECT工作但UPDATE失败。 ? [英] SELECT works but UPDATE fails. ?

查看:84
本文介绍了SELECT工作但UPDATE失败。 ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此声明失败

更新ded_temp a

设置a.balance =(从ded_temp b中选择sum(b.ln_amt)



其中a.cust_no = b.cust_no

和a.ded_type_cd = b.ded_type_cd

和a.chk_no = b.chk_no

group by cust_no,ded_type_cd,chk_no)

出现此错误:

服务器:消息170,级别15,状态1,行1

第1行:'a''附近的语法不正确。

但是这句话:

select * from ded_temp a

where a.balance =(选择总和(b.ln_amt)

来自ded_temp b

其中a.cust_no = b.cust_no

和a。 ded_type_cd = b.ded_type_cd

和a.chk_no = b.chk_no

group by cust_no,ded_type_cd,chk_no)

运行没有错误:

为什么?我应该如何更改第一个语句来运行我的更新。这个

声明当然在Oracle中运行良好。 :)

tks

ken。

This statement fails
update ded_temp a
set a.balance = (select sum(b.ln_amt)
from ded_temp b
where a.cust_no = b.cust_no
and a.ded_type_cd = b.ded_type_cd
and a.chk_no = b.chk_no
group by cust_no, ded_type_cd, chk_no)
With this error:
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near ''a''.
But this statement:
select * from ded_temp a
where a.balance = (select sum(b.ln_amt)
from ded_temp b
where a.cust_no = b.cust_no
and a.ded_type_cd = b.ded_type_cd
and a.chk_no = b.chk_no
group by cust_no, ded_type_cd, chk_no)
Runs without error:
Why? and How should I change the first statement to run my update. This
statement of course works fine in Oracle. :)
tks
ken.

推荐答案


只需这样尝试:


update ded_temp

set balance =(选择总和(b.ln_amt)

来自ded_temp b

其中a.cust_no = b.cust_no

和a.ded_type_cd = b.ded_type_cd

和a.chk_no = b.chk_no

group by cust_no,ded_type_cd,chk_no)


最好问候,

Chandra
http://groups.msn.com/SQLResource/
http://chanduas.blogspot.com/

---- -----------------------------------


***通过开发人员指南 http://www.developersdex.com 发送***
Hi
Just try it out this way:

update ded_temp
set balance = (select sum(b.ln_amt)
from ded_temp b
where a.cust_no = b.cust_no
and a.ded_type_cd = b.ded_type_cd
and a.chk_no = b.chk_no
group by cust_no, ded_type_cd, chk_no)

best Regards,
Chandra
http://groups.msn.com/SQLResource/
http://chanduas.blogspot.com/
---------------------------------------

*** Sent via Developersdex http://www.developersdex.com ***


kalamos(km******@hotmail.com)写道:
kalamos (km******@hotmail.com) writes:
此声明失败
更新ded_temp a
设置a.balance =(从ded_temp中选择sum(b.ln_amt)
b
其中a.cust_no = b.cust_no
和a.ded_type_cd = b.ded_type_cd
和a.chk_no = b.chk_no
分组由cust_no,ded_type_cd,chk_no)
This statement fails
update ded_temp a
set a.balance = (select sum(b.ln_amt)
from ded_temp b
where a.cust_no = b.cust_no
and a.ded_type_cd = b.ded_type_cd
and a.chk_no = b.chk_no
group by cust_no, ded_type_cd, chk_no)




更新ded_temp

设置a.balance =(从ded_temp中选择sum(b.ln_amt)

b

其中a.cust_no = b。 cust_no

和a.ded_type_cd = b.ded_type_cd

和a.chk_no = b.chk_no

group by cust_no,ded_type_cd,chk_no)<来自ded_temp的
a


没有一个语法符合标准SQL,所以不同的引擎

添加了不同的地方你在哪里可以放入别名。


-

Erland Sommarskog,SQL Server MVP, es **** @ sommarskog.se


书籍Onlin e for SQL Server SP3
http: //www.microsoft.com/sql/techinf...2000/books.asp


2005年6月3日星期五00:06:03 - 0400,kalamos写道:
On Fri, 3 Jun 2005 00:06:03 -0400, kalamos wrote:
此声明失败
更新ded_temp a
设置a.balance =(从ded_temp中选择sum(b.ln_amt)
b
其中a.cust_no = b.cust_no
和a.ded_type_cd = b.ded_type_cd
和a.chk_no = b.chk_no
分组由cust_no,ded_type_cd,chk_no)

出现此错误:
服务器:消息170,级别15,状态1,行1
第1行:'a''附近的语法不正确。
This statement fails
update ded_temp a
set a.balance = (select sum(b.ln_amt)
from ded_temp b
where a.cust_no = b.cust_no
and a.ded_type_cd = b.ded_type_cd
and a.chk_no = b.chk_no
group by cust_no, ded_type_cd, chk_no)
With this error:
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near ''a''.



(剪辑)


你好,


Erland已经指出专有的UPDATE FROM语法

不同产品。但是,为什么使用专有代码时,你可以使用几乎所有数据库都可以使用的ANSI标准代码:


update ded_temp

set balance =(选择总和(b.ln_amt)

来自ded_temp b

其中ded_temp.cust_no = b.cust_no

和ded_temp .ded_type_cd = b.ded_type_cd

和ded_temp.chk_no = b.chk_no

group by cust_no,ded_type_cd,chk_no)


顺便说一下,你也可以省略GROUP BY子句,因为子查询只会为一组(cust_no,ded_type_cd,chk_no)的行匹配 - 这个

甚至可能给你一些性能提升!


Best,Hugo

-


(删除_NO_和_SPAM_获取我的电子邮件地址)


(snip)

Hi ken,

Erland already pointed out that the proprietary UPDATE FROM syntax
differs between products. However, why use proprietary code when you can
use ANSI-standard code that will work on almost all databases:

update ded_temp
set balance = (select sum(b.ln_amt)
from ded_temp b
where ded_temp.cust_no = b.cust_no
and ded_temp.ded_type_cd = b.ded_type_cd
and ded_temp.chk_no = b.chk_no
group by cust_no, ded_type_cd, chk_no)

BTW, you can also omit the GROUP BY clause, since the subquery will only
match rows for one set of (cust_no, ded_type_cd, chk_no) anyway - this
might even give you some performance gain!

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)


这篇关于SELECT工作但UPDATE失败。 ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆