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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2007-01-08 : 08:03:31
|
| Maneesh writes "sir i gets the following error message while using itMessage:*--------------------------------------a cursor with the name c2 already exits*---------------------------------------The following function is designed as recursive functionWhen it functions in a large scale , the cursor opened in may not be closed , so this appears...how can i dynamicaly assign the new cursor name for each cursor in sub callTable structure---------------Table name : AccountGMasterFields------Head numeric(9)AcGID numeric(9)GroupName varchar(50)here the value in head will be value of AcGID from a rowie , this table i self linkingi would like to get all subgroups under the particular headcoul u plz suggest any other way?----------------------------------CREATE FUNCTION dbo.ListAccounts (@AcGID numeric) RETURNS @tab table(AID numeric(9),AcName varchar(100)) AS BEGIN declare @A numeric(9),@B varchar(100),@ID numeric(9),@Name varchar(100)declare C1 Cursor for select b.AcGID,b.GroupName from AccountGMaster a inner join AccountGMaster b on a.AcGID=b.Head where a.AcGID=@AcGID open c1fetch next from c1 into @A,@Bwhile @@FETCH_STATUS=0begin declare c2 cursor for select * from ListAccounts(@A) open c2 fetch next from c2 into @ID,@Namewhile @@FETCH_STATUS=0begin insert into @tab([AID],[AcName]) values(@ID,@Name)fetch next from c2 into @ID,@Nameendclose c2fetch next from c1 into @A,@Bendclose c1declare c3 cursor forselect AID,AcName from AccountMaster where AcGID=@AcGIDopen c3fetch next from c3 into @ID,@Namewhile @@FETCH_STATUS=0begin insert into @tab([AID],[AcName]) values(@ID,@Name)fetch next from c3 into @ID,@Nameendclose c3returnEND" |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-08 : 08:43:43
|
| Why don't you tell us what you are trying to do, and I am sure we will come up with a smarter and faster way to accomplish your task.Post sample data and your expected output based on your provided sample data.Peter LarssonHelsingborg, Sweden |
 |
|
|
|
|
|
|
|