社区
MS-SQL Server
帖子详情
[help]一个update sql怎么写
x0y1z2
2005-03-21 10:53:23
create table Test(
pk varchar(10) primary key,
code varchar(12),
year int,
fieldA varchar(20)
fiedlB int
);
表中有2002,2003,2004,2005的数据,每年code大多数一样的,现在要把2005的fieldA,fieldB 改为和2004的相同code对应的fieldA,fieldB
...全文
93
7
打赏
收藏
[help]一个update sql怎么写
create table Test( pk varchar(10) primary key, code varchar(12), year int, fieldA varchar(20) fiedlB int ); 表中有2002,2003,2004,2005的数据,每年code大多数一样的,现在要把2005的fieldA,fieldB 改为和2004的相同code对应的fieldA,fieldB
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
7 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
x0y1z2
2005-03-21
打赏
举报
回复
赫赫,好像是的
ps:你上面的方法可以用的
lsxaa
2005-03-21
打赏
举报
回复
and a.code='0101101010'
and a.code='01011010' 这两个不一样啊
x0y1z2
2005-03-21
打赏
举报
回复
运行
update test set fieldA =a.fieldA ,fiedlB =a.fiedlB
from test as a where code=a.code and year=2005 and a.year=2004
and a.code='01011010'
(0 row(s) affected)
但是运行
select * from test as a ,test as b
where b.code=a.code and b.year=2005 and a.year=2004
and a.code='0101101010'
却有一条记录阿,
我什么地方写错了阿?
lsxaa
2005-03-21
打赏
举报
回复
不支持别名,这样
select * into #t from 表
update test set fieldA=#t.fieldA ,fieldB=#t.fieldB
from #t where test.code=#t.code and test.year=2005 and #t.year=2004
x0y1z2
2005-03-21
打赏
举报
回复
The column prefix 'test' does not match with a table name or alias name used in the query.
但是test 表示有的阿
x0y1z2
2005-03-21
打赏
举报
回复
The column prefix 'test' does not match with a table name or alias name used in the query.
jinjazz
2005-03-21
打赏
举报
回复
update test set fieldA=a.fieldA ,fieldB=a.fieldB
from test a where test.code=a.code and test.year=2005 and a.year=2004
SQL
sp_
help
(Transact-
SQL
)
sp_
help
(Transact-
SQL
)
SQL
Server 2008 R2 其他版本 此主题尚未评级 - 评价此主题 报告有关数据库对象(sys.sysobjects 兼容视图中列出的所有对象)、用户定义...
SQL
触发器(有同步
update
的例子)
SQL
触发器 触发器分为:DML触发器、DDL触发器、登录触发器 原理如表格所示 对表的操作 inserted表 deleted表 增加记录(insert) 存放增加的记录 无 删除记录(delete) 无 存放被删除的记录 修改记录...
利用
Sql
Server触发器自动更新表
update
time字段值
本文主要记录了使用
Sql
Server数据库触发器自动更新表的"更新时间
update
time"字段 在 My
SQL
数据库中,某行数据创建时间字段 createtime 、 行最新更新时间字段
update
time 可建表时分别用"datetime ...
sql
alchemy
update
sql
[CPyUG]
SQL
Alchemy对多条数据批量更新的问题 by Gaicitadie Apr 12, 2010; 11:50pm :: Rate ...)Reply | Print | View Threaded | Show Only this Message假设有
一个
表 News,有
一个
字段tid,部分记录...
MS-SQL Server
34,838
社区成员
254,632
社区内容
发帖
与我相关
我的任务
MS-SQL Server
MS-SQL Server相关内容讨论专区
复制链接
扫一扫
分享
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章