如何将列的值插入SQl Server中的另一列 [英] How Do I Insert The Value Of a Column Into Another Column in SQl Server

查看:191
本文介绍了如何将列的值插入SQl Server中的另一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是名为国内的表有以下列和值





fid mid fname child1 child2



101 1 mohan rajiv sanjiv

102 1 sohan raji kirti

103 1 manoj prem godu

104 1 ram shyam rahim



现在我想将列child1和child2的值插入到'fname'列中,然后表应该是这样的。



fid mid fname



101 1 mohan

101 2 rajiv

101 3 sanjiv

102 1 sohan

102 2 raji

102 3 kirti

103 1 manoj

103 2 prem

103 3 godu

104 1 ram

104 2 shyam

104 3 rahim



如何解决这个问题请帮帮我



thnks

This is table named Domestic have following column and value


fid mid fname child1 child2

101 1 mohan rajiv sanjiv
102 1 sohan raji kirti
103 1 manoj prem godu
104 1 ram shyam rahim

now i want the value of column child1 and child2 should be inserted into column 'fname', then table should look like this.

fid mid fname

101 1 mohan
101 2 rajiv
101 3 sanjiv
102 1 sohan
102 2 raji
102 3 kirti
103 1 manoj
103 2 prem
103 3 godu
104 1 ram
104 2 shyam
104 3 rahim

how can i solve this problem please help me

thnks

推荐答案

你为什么不尝试皮特的解决方案?它只需要一些修改。



why didn't you try pete's solution? it works just needed some modification.

INSERT INTO DOMESTIC(fid, mid, fname)( SELECT fid,2,child1 FROM DOMESTIC UNION ALL SELECT fid,3,child2 FROM DOMESTIC)


这应该有效:
INSERT INTO DOMESTIC(fid, mid, fname) SELECT (fid,2,child1) FROM DOMESTIC
INSERT INTO DOMESTIC(fid, mid, fname) SELECT (fid,3,child2) FROM DOMESTIC


这篇关于如何将列的值插入SQl Server中的另一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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