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.
| Author |
Topic |
|
cool.mugil
Starting Member
32 Posts |
Posted - 2010-07-09 : 01:48:53
|
| Hi,I have a table structure like this below,EmpID Name Mgr1 Mgr2 Mgr3 Mgr41 A 2 3 4 52 B 6 7 8 NULL3 C 8 9 NULL NULL4 D 10 NULL NULL NULL5 E NULL NULL NULL NULL6 F NULL NULL NULL NULL7 G NULL NULL NULL NULL8 H NULL NULL NULL NULL9 I NULL NULL NULL NULL10 J NULL NULL NULL NULLI want the output as followsEmpID Name Mgr1 Mgr2 Mgr3 Mgr41 A B C D EPlease note that some of the mgr fields may be null.how to write query for this.I am using sql server 2005.Thanks in advance.Mugil |
|
|
Devart
Posting Yak Master
102 Posts |
Posted - 2010-07-09 : 02:22:22
|
| Hello,You can try this:select EmpID, Name, (select Name from <your_table_name> where empid=t.mgr1) as mgr1, (select Name from <your_table_name> where empid=t.mgr2) as mgr2, (select Name from <your_table_name> where empid=t.mgr3) as mgr3, (select Name from <your_table_name> where empid=t.mgr4) as mgr4from <your_table_name> tBest regards,Devart Team |
 |
|
|
SD_Monkey
Starting Member
38 Posts |
Posted - 2010-07-09 : 06:30:52
|
if you concern is to not viewing a data with not value on mgryou may condition to it as not nullSelect * from tbl where mgr1 is not null and mgr2 is not null and mgr3 is not null and mgr4 is not null A maze make you much more better |
 |
|
|
|
|
|