0

I shall appreciate some help. I have two tables in an SQL Server. I want to get 2 row level columns should be column level. If I join 2 tables, i am getting Cartesian product.

table 1:

emp_Id    name    age
----------------------
101       aaa     20
102       bbb     30

table 2:

p_id     emp_id     type     ph_no
-----------------------------------
1        101        201      8888
2        101        202      9999
3        101        203      7777
4        102        201      1111
5        102        202      2222
6        102        203      3333

Expected output:

 emp_Id    name    age     201#    203#
 ----------------------------------------
 101       aaa     20      8888    7777
 102       bbb     30      1111    3333
 
Srinivasan
  • 11,718
  • 30
  • 64
  • 92
  • have you tried pivot as earch term? – nbk Jun 28 '22 at 11:41
  • This is called pivoting. There are a lot of similar (duplicate?) questions already. If you know the column values in advance you can use the `PIVOT` clause. Otherwise you'll have to use dynamic SQL – Panagiotis Kanavos Jun 28 '22 at 11:42

0 Answers0