本文介绍了如何将列的值插入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 fnamechild1child2

101 1 mohanrajivsanjiv
102 1 sohanrajikirti
103 1 manojpremgodu
104 1 ramshyamrahim

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

推荐答案

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中的另一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-22 13:07