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

新手求教,批量更改属性的问题。

发布于 2010-05-01 09:18, 501 次点击
Psncode     style     HY_Price  
001          111         2
001          222        10
002          111         1
002          222         9

现在我想把psncode列002里的所有HY_Price列的数值改得和001的一样。也就是说要把002里的111和222的数值分别改成2和10。
要怎么写才行呢。
自己试着用原来的一条简单的批量修改会员价的语句改了一下,大概是这样,不过有语法错误
批量修改会员价的语句是这样的:
update spdaslave set hy_price=actprice * 0.98 where style in (select style from spdamaster where vendcode='0021')
时候试着改成这样
update spdaslave set (select syyle form spdaslave where psncode='001' )hy_price)=(select syyle form spdaslave where psncode='002' )hy_price) where style in (select style from spdamaster where vendcode='0021')
不能运行

这里的vendcode是spdamaster表里的另外一个属性。
请谁来帮帮我,急用,谢谢了

[ 本帖最后由 xlykzylky 于 2010-5-1 09:23 编辑 ]
2 回复
#2
cnfarer2010-05-01 10:38
试试吧!
update table set hy_price=b.hy_price from table a inner join table b on a.style=b.style where a.psncode='002' and b.psncode='001'
#3
aei1352010-05-04 09:32
update spdaslave  
set hy_price=b.hy_price
from spdaslave inner join spdaslave  b
on spdaslave.style=b.style and spdaslave.psncode='002' and b.psncode='001'
1