Hi, I want to map two tables dynamically that have data like below and what kind of result I want is also posted there. Please help me with how I can get this result.
TABLES:
CREATE TABLE #A
(
NAME VARCHAR(10),
NUMBER INT,
ID VARCHAR(5)
)
INSERT INTO #A VALUES ('JOHN', 20,'J10')
CREATE TABLE #B
(PRODUCT VARCHAR(10),
NAME VARCHAR(20)
)
INSERT INTO #B VALUES ('APPLE','JOHN, HARRY'),('ORANGE', 'JOHN,MIKE') ,('MANGO','JOHN, KATTY, ALEX')
The result should be like below:
+--------+-----------+-----------+--------------+---------------------------
|NAME | NUMBER | ID | PRODUCT |
+--------+-----------+-----------+--------------+-------------------------
|JOHN | 20 | J10 | APPLE |
|--------|-----------|--------------|----------------|--------------------------
|JOHN | 20 | J10 | ORANGE |
+--------+-----------+-----------+---------------+------------------------
|JOHN | 20 | J10 | MANGO |
+--------+-----------+-----------+---------------+-------------------------
|MIKE | 2 | M5 | ORANGE |
+--------+-----------+-----------+---------------+-------------------------