Table1
Code, desc, type id
01 Rajan 1
01 Sajan 1
01 Vijayan 2
01 Suresh 3
01 Caresh 4
01 Sujesh 4
01 vikran 4
02 desk 1
02 card 2
02 villa 2
02 megash 2
02 supan 3
....
I want to view the table by type id wise
Expected Output
Code type-1 type-2 type-3 type-4
01 Rajan Vijayan suresh caresh
01 Sajan null null Sujan
01 null null null vikran
02 desk card supan null
02 null villa null null
02 null megash null null
How to make a query for the above condition
Need Query Help
So first off just staging your data up. Note that I'm adding an identity row id for later.
Then we create a holding area that uses that row id to calculate which row of the code each of the names should go on.
Lastly, we create a PIVOT table on the data, (done in a standard SQL 2000 way of "faking" that operator). We then place that "PIVOT table" in a derived select that returns only the columns we want but allows us to sort on the code and rownum columns to generate the output you asked for.
Please let me know if you want further explanation on any of this.
Try this query it will not return null but will return repeated values
contact if you have any doubts