> For the complete documentation index, see [llms.txt](https://brixxbox.gitbook.io/brixxbox-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://brixxbox.gitbook.io/brixxbox-documentation/configuration/apps/sqlfunction.md).

# SqlFunction

### SQL Functions

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.

### Example Usages

Only write the body of the function! Is this case the **CREATE FUNCTION ExampleDateToVeryLongString** is automatictly generated.

```sql
(@DATE datetime) 
RETURNS nvarchar(max)
WITH EXECUTE AS CALLER
AS
BEGIN

	declare @DayAsString nvarchar(max);

    SET @DayAsString =   
        CASE   
            WHEN DAY(@DATE) = 1 THEN '1st'  
            WHEN DAY(@DATE) = 2 THEN '2nd'  
            WHEN DAY(@DATE) = 3 THEN '3rd'  
			ELSE DATENAME(day, @DATE) + 'th'
        END; 

	RETURN( DATENAME(weekday, @DATE) 
	       + ' ' +  @DayAsString + ' of ' 
		   + DATENAME(month, @DATE) 
		   + ' in the Year ' + DATENAME(YEAR, @DATE)
	);
END;
```

\
This Function can be used as part of a SQL Statement. i.g.

```sql
SELECT dbo.ExampleDateToVeryLongString ((GETUTCDATE()))
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://brixxbox.gitbook.io/brixxbox-documentation/configuration/apps/sqlfunction.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
