A function defined in a relational database system. Most RDBS's include numerous built-in functions and also allow for the creation of additional custom functions.
Questions tagged [sql-function]
908 questions
9
votes
2 answers
Function executes faster without STRICT modifier?
I stumbled upon a slump in performance when a simple SQL function is declared STRICT while answering this question.
For demonstration, I created two variants of a function ordering two elements of an array in ascending order.
Test setup
Table with…

Erwin Brandstetter
- 605,456
- 145
- 1,078
- 1,228
8
votes
1 answer
divide the value of a column by another column
I want to divide a value of a column by the value of another column and display the result as separate column
ex:
project name total-percent no.of screen
------------ -------------- -------------
pro-1 …

Sheik Syed Mohaideen
- 191
- 3
- 6
- 15
8
votes
2 answers
How can i cut the left part of the string with unknown legth? (with sql function)
In the ETL process, I receive a varchar field, and the length (of the value) is changed from row to row.
I need to keep 5 symbols from the right side of the string.
It means that I need to cut the left side but I can't, due to the unknown…

Terpsihora
- 83
- 1
- 1
- 3
8
votes
8 answers
Why can we not execute a stored procedure inside a function in SQL Server
Why can we not execute a stored procedure inside a function when the opposite is possible?

user347755
- 139
- 1
- 3
- 7
8
votes
2 answers
EF 6.1 Scalar-Valued Functions Database First
My application is c# MVC5, using EF 6.1. Imported tables and functions using Database First. I can see the function in model (emdx) browser listed under DALModel.Store / Stored Procedures / Functions (grayed out).
I am trying to use the function…

hncl
- 2,295
- 7
- 63
- 129
8
votes
2 answers
How do I create custom sequence in PostgreSQL based on date of row creation?
I am in the process of replacing a legacy order management application for my employer. One of the specs for the new system is that the order numbering system remain in place. Right now, our order numbers are formatted like so:
The first four…

rockusbacchus
- 1,257
- 1
- 12
- 11
8
votes
4 answers
Should SQL functions be uppercase or lowercase?
I am new in SQL and I was wondering what is the right way to write the functions. I know the norm for statements like SELECT is uppercase, but what is the norm for functions? I've seen people write them with lowercase and others in uppercase.
Thanks…

user1919052
- 247
- 2
- 5
- 11
7
votes
3 answers
ExecuteScalar always returns null when calling a scalar-valued function
Why does this return null?
//seedDate is set to DateTime.Now; con is initialized and open. Not a problem with that
using (SqlCommand command = new SqlCommand("fn_last_business_date", con))
{
command.CommandType = CommandType.StoredProcedure;
…

Icarus
- 63,293
- 14
- 100
- 115
7
votes
3 answers
Using function result in WHERE clause in PostgreSQL
I am trying to use result of function execution in where clause but with no success:
SELECT clinics.*, distance_between_objects(1, id, 7, 3) AS dist FROM clinics WHERE dist<=1;
gives me:Column "dist" does not exists.
Quoting it like:
SELECT…

Serj.by
- 534
- 5
- 17
7
votes
2 answers
SQL Server execute (sp_executesql ) command in SQL function
I created a function in SQL Server to execute a dynamic SQL query and return a value. I'm getting error when calling function in SQL query:
Only functions and some extended stored procedures can be executed from within a function
Function: (return…

Sami
- 3,686
- 4
- 17
- 28
7
votes
3 answers
Are execution plan for functions cached in SQL server?
Can any body help me in understanding if the execution plan for functions cached in SQL server?
Any online resource for this?

Ashwani K
- 7,880
- 19
- 63
- 102
7
votes
1 answer
show function definition in mysql
I am working with existing project, and I am found a sql query with sql-function like
SELECT * FROM money WHERE amount = float_convert(0.1);
This Query is Working Properly, But I want to see and edit the function float_convert();
I am already…

Selvaa
- 75
- 1
- 9
7
votes
2 answers
Return multiple values from PL/SQL Function
I need to try and find a free seat on a plane, and then reserve that seat.
I need to return both a value to indicate success or not as well as a seat number. By looking around I've found that functions can't return more than 1 value so I thought…

OmniOwl
- 5,477
- 17
- 67
- 116
7
votes
2 answers
Very Slow SQL Server Query using Functions
This sort of follows on from a previous question:
SQL Server Query time out depending on Where Clause
In which a query would run extremely slowly depending on a where clause. I rewrote that query use CTE and avoided the problem nicely, but never…

Molloch
- 2,261
- 4
- 29
- 48
6
votes
2 answers
Azure Pipelines - CI/CD: How to execute all .sql files in a folder against DB
I have all the SQL files checked into a repo on Azure devops.
I have naming convention that allows me to know which .sql files are used by other .sql files (ex. file creates a view that is used by a stored procedure).
I am wanting to force the use…

michael
- 121
- 1
- 7