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 |
|
Preeti_Mumbai
Starting Member
4 Posts |
Posted - 2011-08-04 : 05:36:01
|
| hi all,i am using CTE, but failed to use with SP;WITH EmpCTE AS(SELECT a.EmployeeId,CAST ('' AS VARCHAR(500)) AS Reporting_HeadsFROM EmpTable aWHEREa.BossId IS NULL UNION ALL SELECT E.EmployeeId,CAST (Ec.reporting_Heads + ',' + CAST(Ec.EmployeeId AS Varchar(200)) AS VARCHAR(500)) AS Reporting_Heads FROM EmpCTE EcINNER JOINEmpTable EONE.BossId = Ec.EmployeeId) SELECT Reporting_Heads FROM EmpCTE WHERE EmpCTE.EmployeeId = 100004i am having emp table.i want to find out Emp BossID,i want to pass EmployeeId Through Store Procedure, which i will be using in C#.net and want result like below mention screen.[url]http://postimage.org/image/1ill0o0bo/[/url]Thanks Preeti |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-08-04 : 06:02:21
|
[code]declare @EmpID intselect @EmpID = 100004; with rcte as( select FullName, EmployeeID, BossID, lvl = 1 from EmpTable where EmployeeID = @EmpID union all select e.FullName, e.EmployeeID, e.BossID, lvl = r.lvl + 1 from EmpTable e inner join rcte r on e.EmployeeID = r.BossID)select BossIDfrom rcteorder by lvl desc[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
Preeti_Mumbai
Starting Member
4 Posts |
Posted - 2011-08-04 : 06:36:12
|
thanks for your quick response dear, your solution is working very fine, only one problem,i don`t want null value in result set.result after your solution executed-:NULL100000100001100002100003but i want result only below mention-:100000100001100002100003thanksquote: Originally posted by khtan
declare @EmpID intselect @EmpID = 100004; with rcte as( select FullName, EmployeeID, BossID, lvl = 1 from EmpTable where EmployeeID = @EmpID union all select e.FullName, e.EmployeeID, e.BossID, lvl = r.lvl + 1 from EmpTable e inner join rcte r on e.EmployeeID = r.BossID)select BossIDfrom rcteorder by lvl desc KH[spoiler]Time is always against us[/spoiler]
|
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-08-04 : 07:44:10
|
just add a WHERE clause and check for NULLwhere BossID is not null KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
Preeti_Mumbai
Starting Member
4 Posts |
Posted - 2011-08-04 : 07:50:43
|
done it,thank you so much for your help.Thanksquote: Originally posted by khtan just add a WHERE clause and check for NULLwhere BossID is not null KH[spoiler]Time is always against us[/spoiler]
|
 |
|
|
|
|
|
|
|