arthurh88
asked on
Quick Help with MSSQL Select comparing dates
I have a table named "users" with these fields:
username
password
expirationdate
hostnames
In my stored procedure I need to verify that the current date is not past the expiration date. If it is, then it should return "expired"
What chunk of code could I use? I'm not sure how to compare dates.
username
password
expirationdate
hostnames
In my stored procedure I need to verify that the current date is not past the expiration date. If it is, then it should return "expired"
What chunk of code could I use? I'm not sure how to compare dates.
ASKER
Hi there. I don't really want a function, I'd rather have an inline code inside my SP, I only want to return in case of expired. I came up with this but I'm getting an error. A fix to this would be ideal.
DECLARE @currentDateTime datetime
If @currentdatetime > select expiration
from Users
where (username = @username)
BEGIN
set @responsestring = "Expired"
RETURN
END
DECLARE @currentDateTime datetime
If @currentdatetime > select expiration
from Users
where (username = @username)
BEGIN
set @responsestring = "Expired"
RETURN
END
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
excellent!
thanks
thanks
create function dbo.GetUserStatus(@Usernam
returns varchar(20)
as
begin
return ( select case when expirationdate < getdate() then 'expired' else 'ok' end from users where username = @username )
end