fjkilken
asked on
Need SQL function to output two dates
Hi
I have a query which outputs a pair of dates based upon the current date - it works just fine but I need to put it into a Function and need help - here is my attempt at writing the Function - thanks for the help!
I have a query which outputs a pair of dates based upon the current date - it works just fine but I need to put it into a Function and need help - here is my attempt at writing the Function - thanks for the help!
CREATE FUNCTION [dbo].[imaps_fn_date2intelcalrng](@intl_mo_strt, @intl_mo_end)
RETURNS DATETIME
AS
BEGIN
DECLARE @intl_mo_strt SMALLDATETIME
DECLARE @intl_mo_end DATETIME
SELECT DISTINCT MIN([intel_strt_dtm]) AS intl_mo_strt, MAX([intel_end_dtm]) AS intl_mo_end
FROM [dbo].[imaps_intel_clndr]
WHERE CAST(intel_yr AS CHAR(4)) + CASE WHEN LEN(intel_mo) = 1 THEN '0' + CAST(intel_mo AS CHAR(2)) ELSE CAST(intel_mo AS CHAR(2)) END =
(
SELECT DISTINCT CAST(intel_yr AS CHAR(4)) + CASE WHEN LEN(intel_mo) = 1 THEN '0' + CAST(intel_mo AS CHAR(2)) ELSE CAST(intel_mo AS CHAR(2)) END AS YearMonth
FROM [dbo].[imaps_intel_clndr]
WHERE [intel_strt_dtm] = CONVERT(VARCHAR, GETDATE(),101)
)
RETURN(@intl_mo_strt, @intl_mo_end)
END
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
perfect - thanks a lot!
you need to get a table-valued return type instead.