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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 sql

Author  Topic 

rameshgoudd
Starting Member

13 Posts

Posted - 2007-12-14 : 04:15:02
hi,

i have a sql database table,

fields are

uid,username,reporingmanagerid
1 Ramesh 2
2 Raju 4

3 Kalyani 1

4 madhu (null)
here reporting manager id is nothing but userid.

now i want to display the username and repotingmanger name(nothing ut username ) for that particular user..
how can i write the query for this ...

and if the user does not have the reporting manger id also..that record(for the 4th record) also should be displayed..how can i do this

Ramesh

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-12-14 : 04:17:16
Did you have the answer over here http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=94155 ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

rameshgoudd
Starting Member

13 Posts

Posted - 2007-12-14 : 04:24:33
quote:
Originally posted by khtan

Did you have the answer over here http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=94155 ?


KH
[spoiler]Time is always against us[/spoiler]





hi that is not working
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-12-14 : 04:29:14
quote:
Originally posted by rameshgoudd

quote:
Originally posted by khtan

Did you have the answer over here http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=94155 ?


KH
[spoiler]Time is always against us[/spoiler]





hi that is not working



than you should reply on that thread


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-12-14 : 04:37:51
What do you mean by it does not work? Have you put some effort by yourself?

-- Prepare Sample data
declare @t table
(
uid int,
username varchar(50),
reporingmanagerid int
)

insert @t
select 1, 'Ramesh', 2 union all
select 2, 'Raju', 4 union all
select 3, 'Kalyani', 1 union all
select 4, 'madhu', null

-- Actual Query
SELECT a.uid, a.username, b.username AS managername
FROM @t a
left OUTER JOIN @t b
ON b.uid = a.reporingmanagerid
where a.username = 'Ramesh'


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -