表名为:COMUST
表结构如下:
Pnumber name Bchno Pset Pact
1 HB500 7901 2404 2369
1 HC300 7901 560 578
1 water 7901 344 349
1 HB500 7902 2422 2479
1 HC300 7902 542 547
1 water 7902 339 372Pnumber 为主键,我想同时更新Bchno 为 7901,name为HB500, Bchno 为 7902,name为HB500的Pact值,并且Bchno 为 7901,name为HB500这条记录的Pact值更新为2404,Bchno 为 7902,name为HB500这条记录的Pact值更新为2422,用SQ语句该怎么做呢?
请教各位高手,很急啊,万分感谢!!!
表结构如下:
Pnumber name Bchno Pset Pact
1 HB500 7901 2404 2369
1 HC300 7901 560 578
1 water 7901 344 349
1 HB500 7902 2422 2479
1 HC300 7902 542 547
1 water 7902 339 372Pnumber 为主键,我想同时更新Bchno 为 7901,name为HB500, Bchno 为 7902,name为HB500的Pact值,并且Bchno 为 7901,name为HB500这条记录的Pact值更新为2404,Bchno 为 7902,name为HB500这条记录的Pact值更新为2422,用SQ语句该怎么做呢?
请教各位高手,很急啊,万分感谢!!!
解决方案 »
- 无法初始化链接服务器 "(null)" 的 OLE DB 访问接口 "Microsoft.Jet.OLEDB.4.0" 的数据源对象
- sql2005附加数据库出错,着急啊,寻求帮助
- 请教建表时如何填写公式
- 为什么text类型字段UPDATE时,W3WP进程锁死?求解
- 请教一个查询问题
- 急急急.如何撤消sql上一步操作,
- 求:生成十六进制样式的客户编号之SQL写法
- 高分求救!!!!在线等。thanks!
- 请教一个很菜的问题回答后马上给分,在SQLSERVER表中插入图片字段使用那条语句,具体如何实现,是不要以前台应用程序实现(最好能用ASP举例)谢了
- sql server登录失败
- MSSQL2000内存暴涨 求分析原因 附图
- 家里两台电脑可以同时联网吗
update tb set pact=2422 where (bchno =7902 and name='HB500')
a
set
Pact=b.Pset
from
tb a,
(select px=ROW_NUMBER()over(partition by Bchno order by GETDATE()),* from tb)b
where
a.Bchno=b.Bchno and a.Pnumber=b.Pnumber
and
b.px=1
select * from tb
-- Author :fredrickhu(小F,向高手学习)
-- Date :2011-12-04 20:14:30
-- Version:
-- Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (Intel X86)
-- Jul 9 2008 14:43:34
-- Copyright (c) 1988-2008 Microsoft Corporation
-- Enterprise Evaluation Edition on Windows NT 5.1 <X86> (Build 2600: Service Pack 3)
--
----------------------------------------------------------------
--> 测试数据:[tb]
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([Pnumber] int,[name] varchar(5),[Bchno] int,[Pset] int,[Pact] int)
insert [tb]
select 1,'HB500',7901,2404,2369 union all
select 1,'HC300',7901,560,578 union all
select 1,'water',7901,344,349 union all
select 1,'HB500',7902,2422,2479 union all
select 1,'HC300',7902,542,547 union all
select 1,'water',7902,339,372
--------------开始查询--------------------------
update
a
set
Pact=b.Pset
from
tb a,
(select px=ROW_NUMBER()over(partition by Bchno order by GETDATE()),* from tb)b
where
a.Bchno=b.Bchno and a.Pnumber=b.Pnumber and a.name=b.name
and
b.px=1
select * from tb
----------------结果----------------------------
/* Pnumber name Bchno Pset Pact
----------- ----- ----------- ----------- -----------
1 HB500 7901 2404 2404
1 HC300 7901 560 578
1 water 7901 344 349
1 HB500 7902 2422 2422
1 HC300 7902 542 547
1 water 7902 339 372(6 行受影响)
*/