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 |
|
kamii47
Constraint Violating Yak Guru
353 Posts |
Posted - 2008-10-27 : 07:01:46
|
| Dear Allthe below code is store procedue.can u explain about below code?pls help meas soon as possible.here i dont have any idea in fetch and Cursor. these function are not understand.regardnazarmlCREATE procedure [dbo].[spgetparentcat_New](@CUSTID AS VARCHAR(50))asDECLARE @CATID AS VARCHAR(50), @PARENID VARCHAR(50)SELECT ParentCategoryID AS CatID INTO #tbl FROM dbo.tblParentCategory WHERE ParentCategoryID IS NULLDECLARE cus CURSOR FORSELECT DISTINCT CategoryId,ISNULL((SELECT TOP 1 ParentCategoryId FROM dbo.tblParentCategoryWHERE ParentCategoryId = CC.CategoryId),'0') AS CAT1FROM dbo.tblCustomerIngredientCategory CC WHERE CustomerID= @CUSTIDOPEN cusFETCH cus INTO @CATID,@PARENIDWHILE @@FETCH_STATUS = 0BEGINPRINT @CATID + ' --- ' + @PARENIDIF @PARENID = '0'BEGININSERT INTO #tbl VALUES (@CATID)ENDWHILE @PARENID <> '0'BEGINSET @CATID = (SELECT TOP 1 ParentCategoryId FROM dbo.tblCategoryWHERE CategoryID = @PARENID)PRINT '*******************'PRINT @CATIDPRINT '*******************'IF @CATID= '0'BEGININSERT INTO #tbl VALUES (@PARENID)PRINT 'BREAK'BREAKENDELSEBEGINPRINT '---------'PRINT 'PARENT INTERCHANED'PRINT '---------'SET @PARENID = @CATIDENDENDSET @CATID = ''SET @PARENID = 'NA'FETCH cus INTO @CATID,@PARENIDENDCLOSE cusDEALLOCATE cusSELECT DISTINCT ParentCategoryID,CategoryName FROM dbo.tblParentCategoryWHERE ParentCategoryID IN (SELECT CatID FROM #tbl)DROP TABLE #tbl [It is posted by one of my friend.I am not good in cursors so please help him]Kamran ShahidSr. Software Engineer(MCSD.Net,MCPD.net)www.netprosys.com |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2008-10-27 : 07:04:59
|
| http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx-------------Charlie |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-10-27 : 07:05:39
|
You can use a recursive CTE. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
kamii47
Constraint Violating Yak Guru
353 Posts |
Posted - 2008-10-27 : 07:06:27
|
[about Transact Charlie ]Kamran ShahidSr. Software Engineer(MCSD.Net,MCPD.net)www.netprosys.com |
 |
|
|
|
|
|