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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Using SProc Results in SProc Issue

Author  Topic 

timgaunt
Posting Yak Master

115 Posts

Posted - 2005-10-04 : 06:41:25
Hi,

I've had a search around the web, forums and everywhere else I can think to get a solution to this and I'm sure I've just missed the obvious so I apologise if I have.

Basically I'm messing around with the Tree's and Hierachy code from Seventh Knight and would like to use the results to get all the relevant categories from the results but whatever I try I get "An INSERT EXEC statement cannot be nested"

Here's what I've got so far:

CREATE TABLE #temptable(
PlaceID int,
URLPath nvarchar(1000),
PlaceName nvarchar(255) default('')

)

insert into #temptable
EXEC Places_Get_ByURLString_Children_NextLayer 'TestArea/TestSubArea/'

select * from #temptable --join to records table... etc
drop table #temptable


Then the SProc (for completeness)

CREATE PROCEDURE Places_Get_ByURLString_Children_NextLayer(
@URLPath nvarchar(1000)
)
AS
--Set @URLPath = 'England/GreaterLondon/'

CREATE TABLE #paths(
path nvarchar(1000),
URLPath nvarchar(1000),
ParentID int,
PlaceID int,
PlaceName nvarchar(255) default('')
)
--Insert the path data
INSERT INTO #paths EXEC Places_Get_All

Declare @nodeId int, @pad nvarchar(100), @lastCnt int

Set @Pad = '0000'
Set @nodeId = 0

IF EXISTS(SELECT PlaceID FROM #paths WHERE URLPath = @URLPath)
Begin
SELECT
@nodeId = PlaceID
FROM
#paths
WHERE
URLPath = @URLPath
End
--Select the children of the current location

Select distinct
B.PlaceID,
A.URLPath,
B.PlaceName
From
#paths as A
Inner Join Places as B
On A.PlaceID = B.PlaceID
Where
A.ParentID = @NodeId

DROP TABLE #paths


Now am I right in saying that this error is coming about because I'm using temp tables within the SProc to build the results and the only way around this is to include all that code in my new SProc (so duplicating the work and maintenance) surely thats not right is it?

Thanks for your advice in advance.

Tim

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2005-10-04 : 08:35:57
Could be a case of too many stored procs. What exactly are all of them returning? Can these be combined into one select statement that uses a set based solution? It seems that each stored proc calls another, that calls another, that fills a temp table.

Perhaps derived tables in your original proc?

Help us help YOU!
Read this blog entry for more details: http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

*need more coffee*
SELECT * FROM Users WHERE CLUE > 0
(0 row(s) affected)
Go to Top of Page

timgaunt
Posting Yak Master

115 Posts

Posted - 2005-10-04 : 09:52:15
Hi Don,

Thanks for your response but I don't believe it is too many SProcs, there's only 2 involed:

The first is Places_Get_ByURLString_Children_NextLayer
This is just selecting all the places from the Place table where the path to that record is ='TestArea/TestSubArea/' (revert to Seventh Knight's code for that). The response is simple:

PlaceID URLPath PlaceName
2185 TestArea/TestSubArea/ Test Sub Town
2187 TestArea/TestSubArea/ Another Test Sub Town

The second SProc is what I'm trying to build atm and that is just to look at the results from Places_Get_ByURLString_Children_NextLayer and return all the (in this case) hotels within that town.

The way I see it is that there are about 5 different versions of this code mostly using the same data so it seems a lot of maintanace to have to update them all in the even of a change, so I was thinking having one which is then referenced would be a simple solution but obviously not :P

If it helps I can paste the SQL for the tables but didn't feel it would be of use.

Tim
Go to Top of Page

timgaunt
Posting Yak Master

115 Posts

Posted - 2005-10-04 : 10:23:17
I've just noticed Places_Get_All in there too, nm. I think I've sorted it. ta.
Go to Top of Page
   

- Advertisement -