Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
UDF params, return values & data conversion
Message
 
 
To
01/04/2004 13:27:59
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00891543
Message ID:
00892496
Views:
18
Hi Piter,

It cannot be done in UDF because it requires execuiting dynamic sql which is not supported in UDFs.

>This (sort of) works:
>
>FUNCTION GetSomethingFromCB (@Res_Nr Char(6),@LineId Integer,@Field VARCHAR(30),@Default VARCHAR(30))
>RETURNS char(30)
>AS
>BEGIN
>	DECLARE @RetVal nVarchar(30)
>	SELECT @RetVal = @Field FROM dbo.CBInvoice
>		Where RES_Nr = @Res_Nr
>		AND LineId   = @LineId
>	IF @Retval = NULL 	
>		SET @Retval  = @Default
>	Return @Retval	
>END
>
>
>But: The returnvalue only works if the server does an implicit conversion, and besides, I don't really want varchar back, when I'm asking for money values.
>
>So I thought something like this might work (which it don't!)
>
>FUNCTION GetSomethingFromCB (@Res_Nr Char(6),@LineId Integer,@Field VARCHAR(30),@ReturnType VARCHAR(30), @Default VARCHAR(30))
>RETURNS @ReturnType
>AS
>BEGIN
>	DECLARE @RetVal @ReturnType
>	SELECT @RetVal = @Field FROM dbo.CBInvoice
>		Where RES_Nr = @Res_Nr
>		AND LineId   = @LineId
>        BEGIN
>	IF @Retval = NULL 	
>		SET @Retval  = @Default
>        END
>        CAST(@Retval AS @ReturnType)
>	Return @Retval	
>END
>
>
>TIA
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform