注册 登录
编程论坛 SQL Server论坛

SQL问题,update 问题,请高手指教!

fwjtjb 发布于 2010-07-28 11:04, 1232 次点击
update Ap_detail set Ap_detail.icamount= from Ap_detail,purbillvouchs where Ap_detail.ccode=purbillvouchs.cdebithead and Ap_detail.cvouchid='02115784'and purbillvouchs.pbvid=6900 and Ap_detail.icamount<>



我写了这样一个语句 可更新的结果 是每个符合Ap_detail.cvouchid='02115784'and purbillvouchs.pbvid=6900 条件的 记录的 icamount 都变成一样的了

而我想要的是 根据purbillvouchs表中purbillvouchs.pbvid=6900 的记录 和Ap_detail.cvouchid='02115784'的记录一一对应起来 更改
11 回复
#2
dearwolf41282010-07-28 13:13
按照你写的语句是应该生成:每个符合Ap_detail.cvouchid='02115784'and purbillvouchs.pbvid=6900 条件的 记录的 icamount 都改变了;但我不明白你写的:"而我想要的是 根据purbillvouchs表中purbillvouchs.pbvid=6900 的记录 和Ap_detail.cvouchid='02115784'的记录一一对应起来 更改 " 这句话的意思,楼主再说明白点,看我会不?
#3
fwjtjb2010-07-28 13:32
就是 purbillvouchs表中的记录是都不相同的  所以我要改变的icamount也应该和purbillvouchs表中的记录对应起来 数据也是不同的
#4
dearwolf41282010-07-28 14:06
你把两张表的视图贴出来一小部分,估计不光我不明白你的意思,其他人也不一定明白,我把你写的看了6遍了,还有点不太明白.应该是你 的where语句的条件设置的不太对,才每按照你的意愿来
#5
fwjtjb2010-07-28 14:33
只有本站会员才能查看附件,请 登录

只有本站会员才能查看附件,请 登录
Ap_detail
#6
dearwolf41282010-07-28 15:52
老大,你把表Ap_detail的Ap_detail.cvouchid,Ap_detail.ccode,Ap_detail.cvouchid等列
        和表purbillvouchs的 ,purbillvouchs.cdebithead ,Ap_detail.cvouchid 等列  列出来就行了,关键是看你的where语句中的列有什么问题没?你where语句中的条件列表中就没几个,别人怎么判断你的where语句的正确性。麻烦你一下!
#7
aei1352010-07-29 21:52
我觉得你的语句写的有问题,应该这样才对,就是要去掉所更新列的别名,你试试看对不对,对了告诉一声啊!
update Ap_detail set icamount= from Ap_detail,purbillvouchs where Ap_detail.ccode=purbillvouchs.cdebithead and Ap_detail.cvouchid='02115784'and purbillvouchs.pbvid=6900 and Ap_detail.icamount<>
#8
aei1352010-07-29 21:53
笔误,是所更新列的表名,呵呵!
#9
aei1352010-07-30 09:23
搞错了,经过测试你的语句语法并无问题,看来可能是你的表的关联键之间的问题吧,那还是得像6楼所说的把update语句所需要的表和列查询出来贴过来看看了
#10
autobot2010-07-30 11:59
而我想要的是 根据purbillvouchs表中purbillvouchs.pbvid=6900 的记录 和Ap_detail.cvouchid='02115784'的记录一一对应起来 更改

是这样嘛?
程序代码:
UPDATE    Ap_detail
SET       ad.icamount=FROM      Ap_detail ad ,purbillvouchs pb
WHERE     Ad.ccode = pb.cdebithead
    and ad.cvouchid = '02115784'
    and pb.pbvid = [color=#800000; font-weight: bold]6900[/color]
    and Ad.icamount <>

你说的一一对应起来更改,没明白什么意思,如果就是把ad.icamount 和 这两个字段不同的全改成一样的,其实我感觉你可以不要最后一个条件?不知道我理解得对不对?
#11
tangyunzhong2010-08-02 09:07
回复 楼主 fwjtjb
你写了这么多,但没有写出这两个表的关联字段,这样我们什么帮你啊!其实你说的这需求很简单的,就是看不明白你的需求而已.
1