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 |
|
ashokvardhan
Starting Member
4 Posts |
Posted - 2007-05-23 : 04:18:49
|
| Hi, I have a table like this and i need the output in the below mentioned format. This info is WRT to your old recursive procedure.CREATE PROCEDURE ReportList@iCode intASSET NOCOUNT ONDECLARE @iReferID int IF NOT EXISTS( SELECT 1 FROM sysobjects WHERE NAME = 'ReferralOutPut' ) CREATE TABLE ReferralOutput( Code int, ReferID int ) SELECT @iReferID = ReportingEmpCode FROM ReportMapper where EmployeeCode = @iCode IF @iReferID IS NOT NULL BEGIN INSERT INTO ReferralOutput SELECT @iCode, @iReferID execute ReportList @iReferID END SELECT ReferID FROM ReferralOutput-- DROP TABLE ReferralOutputGOrefererid code201 204203 206204 207 205 208207 209206 210210 214210 213207 300refererid code201 204204 207 207 209207 300But i am getting only the below outputrefererid code201 204204 207 207 209RegardsAshok |
|
|
PeterNeo
Constraint Violating Yak Guru
357 Posts |
Posted - 2007-05-23 : 07:22:05
|
| Hi Ashok,can u post sample data, desired output for ReportMapper table. Why do u need recursive loop? |
 |
|
|
ashokvardhan
Starting Member
4 Posts |
Posted - 2007-05-25 : 05:14:45
|
| Hi Peter, I have alreay mentioned sample data in my earlier mail. Any way here is the sample data in the reportmapper table which has two columns refererid & coderefererid code201 204203 206204 207 205 208207 209206 210210 214210 213207 300Expected Outputrefererid code201 204204 207 207 209207 300But i am getting only the below outputIncomplete outputrefererid code201 204204 207 207 209 |
 |
|
|
pbguy
Constraint Violating Yak Guru
319 Posts |
Posted - 2007-05-25 : 05:21:36
|
| ur recursive function will work fine if ur referid column is unique..but it has duplicate values so it find the first return row (here 207 is having two entries so the first 207 entry will be taken for that 209 is code and it will seach for 209 referid not 207 again....u have to change the logic. |
 |
|
|
ashokvardhan
Starting Member
4 Posts |
Posted - 2007-05-30 : 04:37:52
|
| Hi,Thanx for the reply, I am implementing this in terms of organizational hierarchy. I am treating referid as boss and code as subordinate. So, the criteria is two people will be reporting to a person i.e., nothing but 207 (refer id).RegardsAshok |
 |
|
|
|
|
|