Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
UDF params, return values & data conversion
Message
 
 
À
01/04/2004 13:27:59
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00891543
Message ID:
00892496
Vues:
17
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--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform