Hi,
I have a table "#TmpTbl1", which is having a column prdintv. this column will have the data like X;Y. I need to split this data into rows and insert into a separate table "#TmpTbl_intv", again based on ID generated in this table, need to populate data in table "#Tmptbl_crssintv".
Output will be like below (See output expected)
Createtable#TmpTbl1(prdid int,prdnamevarchar(50),prdintvnvarchar(50),prdvndvarchar(50))
insertinto#TmpTbl1 values(101,'Laptop', 'X;Y','aaaa')
insertinto#TmpTbl1 values(102,'Mouse', 'X','bbbb')
insertinto#TmpTbl1 values(103,'CPU', 'Y','cccc')
insertinto#TmpTbl1 values(104,'HDisk', 'X;Y;Z','dddd')
insertinto#TmpTbl1 values(105,'PDrive', 'Y;Z','eeee')
prdid | prdname | prdintv | prdvnd |
101 | Laptop | X;Y | aaaa |
102 | Mouse | X | bbbb |
103 | CPU | Y | cccc |
104 | Hdisk | X;Y;Z | dddd |
105 | PDrive | Y;Z | eeee |
Output expected:
--------------------------------------------------------
Createtable#TmpTbl_intv(intv_id int identity(1,1), intv_namenvarchar(50))
Createtable#Tmptbl_crssintv(prdid int,intv_idint)
#TmpTbl_intv
intv_id | intv_name |
1 | X |
2 | Y |
3 | Z |
#Tmptbl_crssintv
prdid | intv_id |
101 | 1 |
101 | 2 |
102 | 1 |
103 | 2 |
104 | 1 |
104 | 2 |
104 | 3 |
105 | 2 |
105 | 3 |