给表加一列

lude8880 2010-04-26 03:40:53
我现在有一个表,有5列,现在从其它表选出一列,他们的行数是相同的,请问怎么融合?

比如 表1 姓名 年龄 性别
存储过程结果是学分
现在想把这四项合并起来一起。。。。
...全文
269 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
请叫我卷福 2010-04-26
  • 打赏
  • 举报
回复
uping
hhhcj 2010-04-26
  • 打赏
  • 举报
回复
i love LZ!
lude8880 2010-04-26
  • 打赏
  • 举报
回复
i love csdn!
喜-喜 2010-04-26
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 htl258 的回复:]
SQL code
--2005


;with t1 as
(
select rn=row_number()over(order by getdate()),* from tb1
)
,t2 as
(
select rn=row_number()over(order by getdate()),合并的列 from tb2
)
select a.*,b.合并的列
f……
[/Quote]

实在没有关联字段的话,就用tony哥的方法吧!!!!
sql_sf 2010-04-26
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 htl258 的回复:]

SQL code
--2005


;with t1 as
(
select rn=row_number()over(order by getdate()),* from tb1
)
,t2 as
(
select rn=row_number()over(order by getdate()),合并的列 from tb2
)
select a.*,b.合并的列
from t1 a
……
[/Quote]
存储过程结果是学分
htl258_Tony 2010-04-26
  • 打赏
  • 举报
回复
哪果是加进去:

alter table tb1 add 添加的列名 数据类型
go
;with t1 as
(
select rn=row_number()over(order by getdate()),* from tb1
)
,t2 as
(
select rn=row_number()over(order by getdate()),合并的列 from tb2
)
update t1 set
t1.刚才添加进去的列=t2.要复制数据过来的列
from t2
where t1.rn=t2.rn
tiantian789456 2010-04-26
  • 打赏
  • 举报
回复
路过,顶下
htl258_Tony 2010-04-26
  • 打赏
  • 举报
回复
--2005


;with t1 as
(
select rn=row_number()over(order by getdate()),* from tb1
)
,t2 as
(
select rn=row_number()over(order by getdate()),合并的列 from tb2
)
select a.*,b.合并的列
from t1 a
join t2 b
on a.rn=b.rn
sql_sf 2010-04-26
  • 打赏
  • 举报
回复
这个设计...
如果可能修改下你的逻辑吧
如果非要这样
把存储过程结果放临时表,加个自增列
把表1的结果也放临时表,加自增列
然后关联

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧