I work at a college in London and for some reason no one has added a function to call the current academic year within our SQL Server 2008 instance. I had done this successfully in the past on an Oracle server so I thought, how hard can it be, right?
It is only after a failed attempt of my own I realize it isn't as easy as I thought it would be.
My code so far:
USE [DashboardData]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [fea].[current_academic_year]
()
RETURNS int
AS
BEGIN
DECLARE @Result as int
IF Month(GETDATE())<8
SET @Result= Year(GETDATE())-1
ELSE
SET @Result = Year(GETDATE())
RETURN @Result
END
Now, that looks simple enough to me - and it compiles. However, when I call the function in a simple query (on the same database):
Select fea.[current_academic_year]
I get the following error message:
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "FEA.current_academic_year" could not be bound.
Having hardly ever used SQL Server before and after consulting Google, work-colleagues (who stare off into the distance) and former colleagues I am still without an answer. How and why is this happening?
Change:
Select fea.[current_academic_year]
To this:
SELECT [fea].[current_academic_year]()
You are missing ()
, remember this is a scalar-valued function, not a column name.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments