this is killing me..i have a feeling i am over thinking it. I am trying to return a recordset in a string value. I will explain further...
This is a representation of my DB
Now, using a udf with recursion I have no problem returning a recordset of children(and grand children, etc...) for a particular element. For example... udfgetchildren(1) returns
which is great. But I also need to get a string representation of that like 1,2,3,4,5,6,7,8. I could do this code side but i am concerned about the processing time as the db grows.
I attempted a variation on the udfgetchildren called udfgetchildrenlist which would seem to work except one major problem it gives me an error "Error: 'udfgetchildrenlist' is not a recognized builtin function name." since I am using udfgetchildrenlist as a built in. My code is below.. for that udf.
Any ideas on how to get a string? I am not married to any ideas right now so any help would be appreciated.
This is a representation of my DB
Code:
[u]ElementPK,ElementParent[/u]
1,0
2,1
3,2
4,2
5,2
6,3
7,4
8,5
Code:
1
2
3
4
5
6
7
8
which is great. But I also need to get a string representation of that like 1,2,3,4,5,6,7,8. I could do this code side but i am concerned about the processing time as the db grows.
I attempted a variation on the udfgetchildren called udfgetchildrenlist which would seem to work except one major problem it gives me an error "Error: 'udfgetchildrenlist' is not a recognized builtin function name." since I am using udfgetchildrenlist as a built in. My code is below.. for that udf.
Code:
create function udfgetchildrenlist(@ElementID int)
returns varchar(1000)
as
begin
DECLARE @ElementIDList varchar(1000)
SELECT @ElementIDList = CONVERT(varchar(20),@ElementID)
DECLARE cur_Level CURSOR LOCAL FOR
SELECT Element_IDPK FROM tblElement
WHERE Element_parent = @ElementID
OPEN cur_Level
FETCH NEXT FROM cur_Level INTO @ElementID
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @ElementIDList = udfgetchildrenlist(@ElementID)
FETCH NEXT FROM cur_Level INTO @ElementID
END
CLOSE cur_Level
DEALLOCATE cur_Level
return @ElementIDList
end
Any ideas on how to get a string? I am not married to any ideas right now so any help would be appreciated.