March 12, 2007 at 10:11 pm
Hi,
I need to make the following query into a function- I thought it'd be easy, but I keep getting errors. (maybe starting too late at night?)
Can someone help me? Thanks, J
select
cASE WHEN ( MONTH(GetDate())<6 and Day(GetDate())<16)
then
year(getdate())-1
Else
year(getdate()) END as 'year'
March 12, 2007 at 11:50 pm
I got no errors when running what you posted.
--Jeff Moden
Change is inevitable... Change for the better is not.
March 13, 2007 at 11:47 pm
Right- it works fine as a select statement. I want to take it and turn it into a function so I only need to call it one time.
March 14, 2007 at 6:20 am
GETDATE() won't work inside an SS2000 function because of silly rules about being non-deterministic and all... you need to make a view for a simple GETDATE() ...
CREATE VIEW dbo.Now
AS
SELECT GETDATE() AS Now
Then, your code for the function would look like this...
SELECT CASE
WHEN MONTH(Now)<6 AND DAY(Now)<16
THEN YEAR(Now)-1
ELSE YEAR(Now)
END AS 'YEAR'
FROM dbo.Now
I believe SS2005 allows GETDATE() in a function, though.
--Jeff Moden
Change is inevitable... Change for the better is not.
March 14, 2007 at 4:31 pm
Ok... so did that do the trick for you or what? A little feedback goes a long way around here...
--Jeff Moden
Change is inevitable... Change for the better is not.
March 14, 2007 at 11:31 pm
Yes, thanks for your help- I did get it working. Sorry it took so long to respond- I'm telecommuting after coming off maternity leave and am working some very whacky hours!
March 15, 2007 at 6:59 am
Heh... going back to the other posts, I see that now...
Hope things are going well for Mother and Child.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply