Click here to Skip to main content
15,905,776 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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
Posted
Comments
Swaminathan_K 10-Jul-12 0:33am    
Do you have any identity column in these tables?
Member 8244101 10-Jul-12 1:21am    
The table XYZ is having an identity column id separately,u can call that one by the name Column14

1 solution

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.
 
Share this answer
 
Comments
Member 8244101 10-Jul-12 1:21am    
I didn't get u.Can u please be more elaborative.
preet88 10-Jul-12 5:19am    
i've broken your table further into above written attributes
first table will have 3 columns
and second will have 4 columns
suppose you want to store data of your given example then it can be as here::
col1 col2 col3(FK) col1(PK) col11 col12 col13
xxxx xxxx 1 1 a b c
xxxx xxxx 2 2 a1 b1 c1
now whenever you want to receive data of lets say first row of first table then you can apply join on these two tables based on refrenced key
i hope you'll get solution to your problem...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900