SQL Server 2008 Function for Current Academic Year

Alan Tindall

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?

JonH

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Custom function with check constraint SQL Server 2008

From Dev

Sql Server 2008, Select dates of current week in a generic query?

From Dev

Split function by comma in SQL Server 2008

From Dev

how to call scalar function in sql server 2008

From Dev

how to write function sql server 2008

From Dev

Subtraction in SQL Server 2008

From Dev

Alternate of lead lag function in SQL Server 2008

From Dev

SQL Server: replace year of datetime with current year in Select

From Dev

month year sql server 2008 order by date

From Dev

SQL Server 2008 Function for Current Academic Year

From Dev

How to Generate Alphanumeric Random numbers using function in SQL Server 2008

From Dev

How to retrieve dropped stored procedure, function, table in SQL Server 2008

From Dev

how to calculate number of days in year in sql server 2008

From Dev

Creating a function to return results from a table in SQL Server 2008

From Dev

How to use LAG FUNCTION in SQL SERVER 2008

From Dev

Mimic STRING_SPLIT without custom function in SQL Server 2008

From Dev

Split function by comma in SQL Server 2008

From Dev

how to convert scalar into inline function sql server 2008

From Dev

Single Query to get values from Sql server 2008 table based on Birthdate(dd/mmm). User will not specify Year

From Dev

not able to change selected value in dropdown list for current academic year

From Dev

Alternate of lead lag function in SQL Server 2008

From Dev

How to get the Current Year to Current date in sql server 2008

From Dev

Creating function error sql server 2008

From Dev

SQL Language to set a year from the current year

From Dev

How to Generate Alphanumeric Random numbers using function in SQL Server 2008

From Dev

How to use LAG FUNCTION in SQL SERVER 2008

From Dev

How to show data from this month same month last year same period SQL Server 2008

From Dev

How to get percentage between current and previous rows in SQL Server 2008

From Dev

SQL Server:sum rows by year and name the row value as 'current' for current year and 'previous' for last year

Related Related

  1. 1

    Custom function with check constraint SQL Server 2008

  2. 2

    Sql Server 2008, Select dates of current week in a generic query?

  3. 3

    Split function by comma in SQL Server 2008

  4. 4

    how to call scalar function in sql server 2008

  5. 5

    how to write function sql server 2008

  6. 6

    Subtraction in SQL Server 2008

  7. 7

    Alternate of lead lag function in SQL Server 2008

  8. 8

    SQL Server: replace year of datetime with current year in Select

  9. 9

    month year sql server 2008 order by date

  10. 10

    SQL Server 2008 Function for Current Academic Year

  11. 11

    How to Generate Alphanumeric Random numbers using function in SQL Server 2008

  12. 12

    How to retrieve dropped stored procedure, function, table in SQL Server 2008

  13. 13

    how to calculate number of days in year in sql server 2008

  14. 14

    Creating a function to return results from a table in SQL Server 2008

  15. 15

    How to use LAG FUNCTION in SQL SERVER 2008

  16. 16

    Mimic STRING_SPLIT without custom function in SQL Server 2008

  17. 17

    Split function by comma in SQL Server 2008

  18. 18

    how to convert scalar into inline function sql server 2008

  19. 19

    Single Query to get values from Sql server 2008 table based on Birthdate(dd/mmm). User will not specify Year

  20. 20

    not able to change selected value in dropdown list for current academic year

  21. 21

    Alternate of lead lag function in SQL Server 2008

  22. 22

    How to get the Current Year to Current date in sql server 2008

  23. 23

    Creating function error sql server 2008

  24. 24

    SQL Language to set a year from the current year

  25. 25

    How to Generate Alphanumeric Random numbers using function in SQL Server 2008

  26. 26

    How to use LAG FUNCTION in SQL SERVER 2008

  27. 27

    How to show data from this month same month last year same period SQL Server 2008

  28. 28

    How to get percentage between current and previous rows in SQL Server 2008

  29. 29

    SQL Server:sum rows by year and name the row value as 'current' for current year and 'previous' for last year

HotTag

Archive