all groups > sql server programming > june 2007 >
You're in the

sql server programming

group:

where to put OPTION (MAXRECURSION 100) in an UDF ?


Re: where to put OPTION (MAXRECURSION 100) in an UDF ? SQL Menace
6/20/2007 7:34:52 PM
sql server programming:
On Jun 20, 3:03 pm, "Sagaert Johan" <REMOVEsagaer...@hotmail.com>
[quoted text, click to view]

AFAIK MAXRECURSION is used with common table expressions (CTE's) not
with functions

Denis The SQL Menace
http://sqlservercode.blogspot.com
http://sqlblog.com/blogs/denis_gobo/default.aspx
Re: where to put OPTION (MAXRECURSION 100) in an UDF ? Gail Erickson [MS]
6/20/2007 7:56:29 PM
[quoted text, click to view]

Unfortunately, OPTION (MAXRECURSION limit) is not allowed in the definition
of views or user-defined functions. This restriction may be removed in a
future release.

--
Gail Erickson [MS]
SQL Server Documentation Team
This posting is provided "AS IS" with no warranties, and confers no rights
Download the latest version of Books Online from
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx

[quoted text, click to view]

where to put OPTION (MAXRECURSION 100) in an UDF ? Sagaert Johan
6/20/2007 9:03:36 PM
Hi

I recoded a stored procedure into an UDF , where do i put the Maxrecusion
option ?

In my old stored procedure i did put it richt behind the last select, but in
the UDF version i get an error.: Incorrect syntax near the keyword OPTION
ALTER FUNCTION dbo.GetPartsInDesign

(

@designid int,

@designquantity int=1

)

RETURNS TABLE

AS

RETURN

WITH Ingredientlist (DesignID,ProdID) AS

(

SELECT a.DesignID,a.ProdID FROM DesignItems AS a WHERE a.DesignID=@designid

UNION ALL

SELECT a.DesignID, a.ProdID FROM DesignItems AS a

INNER JOIN Ingredientlist AS b ON b.ProdID=a.DesignID

)

SELECT A.ProdID,@designquantity * COUNT(A.ProdID) as Quantity ,( SELECT
ShortName FROM StockParts WHERE (ProdID = A.ProdID) ) as Partname FROM
Ingredientlist AS B RIGHT OUTER JOIN

Ingredientlist AS A ON A.ProdID = B.DesignID GROUP BY A.ProdID,B.ProdID
HAVING B.ProdID IS NULL

// OPTION (MAXRECURSION 100) gives me an errer





Re: where to put OPTION (MAXRECURSION 100) in an UDF ? Sagaert Johan
6/20/2007 11:14:03 PM
just to say , besides the issue with the OPTION the function works
correctly.


[quoted text, click to view]

AddThis Social Bookmark Button