SQL SERVER-要获取插入到另一个表中的数据以获取具有多个值的三列 [英] SQL SERVER - To get the data inserted in another table for three columns having multiple values

查看:103
本文介绍了SQL SERVER-要获取插入到另一个表中的数据以获取具有多个值的三列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

现在,我必须对MS SQl SERVER 2008感到真正的困惑.

解释场景-我有一个具有5列的表ABC(Column1,Column2 ..... Column5).我还有一个具有三列的表XYZ(Column11,Column12,Column13)".

我需要做的是我有3列,即tbale ABC的Column3,column4,column5,在同一行下接收多个值,例如column3和A2的A:B:C,Column4和A2的A1:B1:C1; column5.我必须将这些值插入到XYZ中,以使Column3映射表XYZ的Column11,Coulmn4映射Column12和Column5的映射Column13. 表ABC
列1列2列3列4列5
xxxx xxxx A:B:C A1:B1:C1 A2; B2:C2


表XYZ
Column11 Column12 Column13
A A1 A2
B B1 B2
C C1 C3


现在真正的事情就在这里,以这种方式插入表,使得ABC中具有上述值的行应创建3个具有值A1,A2,A3的行;第11列,第12列和第13列的B1,B2,B3和C1,C2,C3分别是XYZ表中每个值的平均独立行"

任何人都可以通过临时表或视图或其他方式帮助我解决此问题.
P.S:尝试避免在ABC中大约10行具有不同值组合的光标发生相同情况

谢谢
Utkarsh

Hi All,

Right now ,I have to somthing really wierd in MS SQl SERVER 2008.

Explaining the scenario - "I have a table ABC with 5 columns (Column1,Column2.....Column5).I have one another table XYZ with three columns(Column11,Column12,Column13)".

What i need to do is "I have 3 columns namely Column3 ,column4,column5 of tbale ABC recieving multiple values under the same row like A:B:C for column3 ,A1:B1:C1 for Column4 and A2;B2:C2 for column5. I have to get these values inserted into the XYZ in such a way that Column3 maps Column11,Coulmn4 maps Column12 and Column5 maps Column13 of table XYZ.
Table ABC
Column1 Column2 Column3 Column4 Column5
xxxx xxxx A:B:C A1:B1:C1 A2;B2:C2

to
Table XYZ
Column11 Column12 Column13
A A1 A2
B B1 B2
C C1 C3


Now the real thing lies in this,the insertion to the table is made in such a way that A row in ABC with above values should create 3 rows with values A1,A2,A3 ; B1,B2,B3 and C1,C2,C3 respectively for Columns 11 Column12 and Column13 respectively i.e mean separate row for each value in XYZ table"

Can anybody please help me out to handle this thing either through temp table or view or something else.
P.S : try to avoid Cursor an same should happen for around 10 rows in ABC having different combination of values

Thanks
Utkarsh

推荐答案

将表ABC设为
col1,col2,col3(表示XYZ表主键的col1的外键)

XYZ的属性
col1(主键),col11,col12,col13

这样可以解决您的问题.
谢谢.
take your table ABC as
col1, col2, col3 (foriegn key that refers col1 of XYZ table''s primary key)

attributes for XYZ
col1(primary key), col11,col12,col13

this will resolve your problem.
thanks.


这篇关于SQL SERVER-要获取插入到另一个表中的数据以获取具有多个值的三列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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