Reputation: 447
I have a function which calls a CLR assembly
CREATE FUNCTION [dbo].[fGetUTCDate](@LocalDate [datetime])
RETURNS [datetime] WITH EXECUTE AS CALLER
AS
EXTERNAL NAME [MyAssembly].[MyClassName].[GetUTCDateTime]
GO
I need to add conditional statement inside this function like if @LocalDate is a particular date then return some other value else use the assembly, like:
CREATE FUNCTION [dbo].[fGetUTCDate](@LocalDate [datetime])
RETURNS [datetime] WITH EXECUTE AS CALLER
AS
BEGIN
RETURN
CASE WHEN @LocalDate = 'xxxxx' THEN 'XYZ' ELSE
EXTERNAL NAME [MyAssembly].[MyClassName].[GetUTCDateTime]
END
END
GO
However, it seems I cannot add conditional statements inside this function.
My restrictions in current requirement are: a) I cannot modify the assembly b) The function is used in more than 250 SPs so I cannot create another function which calls this external function.
Is there any other way possible to achieve my requirement?
Thanks
Upvotes: 0
Views: 28
Reputation: 2882
You can
1) Rename existing function
2) Create a new function with IF logic with the old name that calls the old function
Upvotes: 3