在sql server中将表更新为另一个 [英] Update table from one to another in sql server

查看:89
本文介绍了在sql server中将表更新为另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,



我有两张桌子

首先是

Id FileId

1 20

2 30

3 40

4 50

5 66

6 45

7 4545

8 58

9 454

10 4

11 12

12 75

13 65

14 21

15 87



和第二个

Id fileId

1 45

2 66

3 58

4 454

5 4

6 4545



我想更新第一个表从5到10 id从6 ID第二个表输出应该如下

Id FileId

1 20

2 30

3 40

4 50

5 45

6 66

7 58

8 454

9 4

10 4545

11 12

12 75

13 65

14 21

15 87



FileId of ID 5到10的表1由第二个ta的FileId替换ble。



谢谢和问候

Mohd Wasif



删除了SHOUTING - OriginalGriff [/ edit]

解决方案

 更新 table1 < span class =code-keyword> SET  table1.FileId =( SELECT  table2.fileId  FROM  table2  WHERE  table2.Id =(table1.Id  -   4 )) WHERE  table1.Id  BETWEEN   5   AND   10 ; 

SELECT * FROM table1


Hi Mohad



这可以帮到你。

link [ ^ ]


HI,

I have two table
First as
Id FileId
1 20
2 30
3 40
4 50
5 66
6 45
7 4545
8 58
9 454
10 4
11 12
12 75
13 65
14 21
15 87

and Second as
Id fileId
1 45
2 66
3 58
4 454
5 4
6 4545

I want to update first table from 5 to 10 id from 6 ids of second table output should be like below
Id FileId
1 20
2 30
3 40
4 50
5 45
6 66
7 58
8 454
9 4
10 4545
11 12
12 75
13 65
14 21
15 87

FileId of table 1 from ID 5 to 10 are replaced by FileId of second table.

Thanks & Regards
Mohd Wasif

[edit]SHOUTING removed - OriginalGriff[/edit]

解决方案

UPDATE table1 SET table1.FileId = (SELECT table2.fileId FROM table2 WHERE table2.Id = (table1.Id - 4)) WHERE table1.Id BETWEEN 5 AND 10;

SELECT * FROM table1


Hi Mohad

May this will help you .
link[^]


这篇关于在sql server中将表更新为另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆