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 |
yhchan2005
Starting Member
26 Posts |
Posted - 2007-11-12 : 04:16:16
|
i had posted the same question in SQL2005 forum and get the answer using CTE, but CTE is not available in SQL2000. Just to check anysolution for below problem ? Thanks in Advance.Hi, i got below sp which will calling back itself ( recursive ) in order to generate the hierarchy. Inside sp, i need to use cursor to hold therecord for looping. The problem is when i execute this sp, SQL server will raise error telling me the cursor already exists or open. Because this is a recursive sp, how can i declare the cursor to avoid error ? or any other way to do it ? Please Help.ALTER proc [dbo].[cpGetHierarchyDetail] (@vcPath varchar(1000),@vcCompanyCode varchar(10),@vcInvNo varchar(50))asDeclare @vcPath varchar(1000)Declare @vcSourceNo varchar(50)Declare @vcSourceCompanyCode varchar(10)Declare @vcType varchar(1)Declare @vcImpExpTrn varchar(1)Set @vcPath = @vcPathif @vcInvNo = '' return-- Declare Cursor to hold the Source Record-- In some cases, it might contain more than 1 record Declare csSource Cursor FOR Select InvoiceNo, CompanyCode, Type, ImpExpTrn, SourceNo, SourceCompanyCodefrom hoCombineSourceWhere CompanyCode = @vcCompanyCodeand InvoiceNo = @vcInvNoOpen csSourceFetch Next From csSource Into @vcInvNo, @vcCompanyCode, @vcType, @vcImpExpTrn,@vcSourceNo, @vcSourceCompanyCodeWhile @@Fetch_Status = 0 begin Set @vcPath = @vcPath + '\' + @vcInvNoInsert into #tTemp(Path, CompanyCode, Type, ImpExpTrn)Values(@vcPath, @vcCompanyCode, @vcType, @vcImpExpTrn)-- Call back the same SP to continueexec dbo.cpGetHierarchyDetail @vcPath, @vcSourceCompanyCode, @vcSourceNoFetch Next From csSource Into @vcInvNo, @vcCompanyCode, @vcType, @vcImpExpTrn,@vcSourceNo, @vcSourceCompanyCodeendClose csSourceDeallocate csSource |
|
spirit1
Cybernetic Yak Master
11752 Posts |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-11-12 : 07:03:15
|
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=92454MadhivananFailing to plan is Planning to fail |
 |
|
Jeff Moden
Aged Yak Warrior
652 Posts |
Posted - 2007-11-12 : 09:11:29
|
Another good source of info is Books Online... lookup "Expanding Hierarchies"...--Jeff Moden |
 |
|
|
|
|
|
|