Useful UserDefined Functions (UDF) : SQL

We often require commonly used user defined function in SQL
So here they are at one common place I found them useful.


For example
Determine Leap Year Function
There will be times when you will need to determine the number of days in a year. This can be the case when you need to compute for the interest of savings accounts in banks. This should be simple enough because it is either 365 days if it is not a leap year and 366 if it is a leap year. Now the problem is determining if a year is a leap year or not. Currently, there is no date function within SQL Server that determines if a year is a leap year or not.
The user-defined function below determines whether a particular date is of a leap year or not. It takes a DATETIME parameter and return a bit flag, which determines if the date is within a leap year or not. A return value of 1 means that it is a leap year while a return value of 0 means it is not a leap year.

here is the link for the entire article
http://www.sql-server-helper.com/functions/index.aspx

0 comments: