MarkLappin
IS-IT--Management
Howdy,
I am attempting to write a UDF which I can use to check to see if a member is currently active in our organization; right now this is a simple datediff by month but the definition of an active member may and will change so the logic to calculate and active member I want to be centrally stored and then use the function to calculate if the member is or is not active so that logic is stored on one placed.
So there are several different ways which this needs to happen right now and thats is we want to count how many members expired in month previously, the current one, or some future one, so I've written a UDF which I'm attempting to use and will be pasted below. All I want this to do is return a bit value indicating if the member is active. Here is the trouble I am having:
IF the function is not passed a date, it uses GETDATE() otherwise it uses the date passed in as an argument. In the parameter list, GETDATE() will not "compile" BUT GETDATE will but does not work.
The full UDF is below and any suggestions/solutiosn will be much appreciated!
I'm developing on SQL 2000 Personal Edition off an Enterprise Install CD -- there are two target environments, one is a SQL 2000 Standard SP4 on 2003 SP1 server, and the other is a SQL Enterprise 2000 SP4 shared hosting environment.
--Mark
CREATE FUNCTION [dbo].[mbr_isActive] (@memberNumber int, @expDateCheck dateTime = GETDATE)
RETURNS bit AS
BEGIN
DECLARE @isActive as bit
SELECT @isActive = (SELECT 0)
DECLARE @expDate as datetime
SELECT @expDate = (SELECT dateExpire from mbrMembership WHERE memberNumber = @memberNumber)
DECLARE @diffAmt as int
SELECT @diffAmt = (SELECT DATEDIFF(mm, @expDateCheck, @expDate))
SELECT @isActive = (SELECT CASE
WHEN @diffAmt >= 0 THEN 1
WHEN @diffAmt < 0 THEN 0
END)
RETURN @isActive
END
I am attempting to write a UDF which I can use to check to see if a member is currently active in our organization; right now this is a simple datediff by month but the definition of an active member may and will change so the logic to calculate and active member I want to be centrally stored and then use the function to calculate if the member is or is not active so that logic is stored on one placed.
So there are several different ways which this needs to happen right now and thats is we want to count how many members expired in month previously, the current one, or some future one, so I've written a UDF which I'm attempting to use and will be pasted below. All I want this to do is return a bit value indicating if the member is active. Here is the trouble I am having:
IF the function is not passed a date, it uses GETDATE() otherwise it uses the date passed in as an argument. In the parameter list, GETDATE() will not "compile" BUT GETDATE will but does not work.
The full UDF is below and any suggestions/solutiosn will be much appreciated!
I'm developing on SQL 2000 Personal Edition off an Enterprise Install CD -- there are two target environments, one is a SQL 2000 Standard SP4 on 2003 SP1 server, and the other is a SQL Enterprise 2000 SP4 shared hosting environment.
--Mark
CREATE FUNCTION [dbo].[mbr_isActive] (@memberNumber int, @expDateCheck dateTime = GETDATE)
RETURNS bit AS
BEGIN
DECLARE @isActive as bit
SELECT @isActive = (SELECT 0)
DECLARE @expDate as datetime
SELECT @expDate = (SELECT dateExpire from mbrMembership WHERE memberNumber = @memberNumber)
DECLARE @diffAmt as int
SELECT @diffAmt = (SELECT DATEDIFF(mm, @expDateCheck, @expDate))
SELECT @isActive = (SELECT CASE
WHEN @diffAmt >= 0 THEN 1
WHEN @diffAmt < 0 THEN 0
END)
RETURN @isActive
END