Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SSIS and Import/Export (2008)
 About SQL prodecures to deal with strings

Author  Topic 

elaine
Starting Member

6 Posts

Posted - 2012-01-19 : 17:13:37
Hi everyone,

Currently I have one problem for, dealing with excel table. I want to import the table into the My SQL Database and join it with other table. Currently, for 1st table, I need to extract the id and product columns, then join with other tables by product.

The problem is: Some id corresponds to multiple products, which makes me hard to join by matching product with tables.

Now I want to modify the 1st table to make sure one id correspond to one product in one rows. So that id 1 product: A;B;C in one row becomes:
id 1 product: A id 1 product B id 1 product C in three rows.

I know it may need loops to realize this, but can not make it work by myself. Does anyone can help me?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-01-19 : 17:45:49
Why does an id that corresponds to multiple products make it hard to join?

Please post some sample so that we can see exactly what you want. We need sample data for all related tables as well as expected output.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

elaine
Starting Member

6 Posts

Posted - 2012-01-22 : 11:41:06
Hi Tara,

Thanks a lot for your reply. I did see how to update a file in the forum...So the data sample is as follows:


original data the final data table needed
id product id product
1 A 1 A
2 A;B;C 2 A
3 D;B 2 B
4 C;F 2 C
5 B 3 D
6 D;E;J 3 B
7 M 4 C
8 G;H;O 4 F
9 I;Q;P 5 B
10 N 6 D
11 G;H;O 6 E
12 H 6 J
13 R 7 M
14 I;T;O 8 G
15 P;J;K 8 H
16 E 8 O
17 I;M;L 9 I
18 Q 9 Q
19 A;J;P 9 P
20 E;U;K 10 N
21 P;H;I 11 G
11 H
11 O
12 H
13 R
14 I
14 T
14 O
15 P
15 J
15 K
16 E
17 I
17 M
17 L
18 Q
19 A
19 J
19 P
20 E
20 U
20 K
21 P
21 H
21 I
Go to Top of Page
   

- Advertisement -