This app allows you to maintain SQL functions for your workspace DataBase.
In the main editor window you can edit the body of the function. The Create/Alter and function name must be omitted. After saving the Function it will be checked for errors. If no Errors are found it will be added to your DataBase.
It is always good practice to add a brief description for your function. This description is searchable within the function list.
Once the function is successfully added to your DataBase you can directly test it from the query window. Enter your test and execute it. Errors or results will be shown. If u enter multiple tests in the query window, select the one you want by marking the relevant text. If a selection is active, only this will be executed.
Only write the body of the function! Is this case the CREATE FUNCTION ExampleDateToVeryLongString is automatictly generated.
WITH EXECUTE AS CALLER
declare @DayAsString nvarchar(max);
SET @DayAsString =
WHEN DAY(@DATE) = 1 THEN '1st'
WHEN DAY(@DATE) = 2 THEN '2nd'
WHEN DAY(@DATE) = 3 THEN '3rd'
ELSE DATENAME(day, @DATE) + 'th'
RETURN( DATENAME(weekday, @DATE)
+ ' ' + @DayAsString + ' of '
+ DATENAME(month, @DATE)
+ ' in the Year ' + DATENAME(YEAR, @DATE)
This Function can be used as part of a SQL Statement. i.g.
SELECT dbo.ExampleDateToVeryLongString ((GETUTCDATE()))