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
29
votes
4 answers
Entity Framework 6 Code First function mapping
I want integrate Entity Framework 6 to our system, but have problem.
I want to use Code First. I don’t want to use Database First *.edmx file for other reasons.
I use attribute mapping [Table], [Column] and this works fine
Database has many…

Alexey
- 291
- 1
- 3
- 5
25
votes
1 answer
What is the difference between prepared statements and SQL or PL/pgSQL functions, in terms of their purpose?
In PostgreSQL, what is the difference between a prepared statement and a SQL or PL/pgSQL function, in terms of their purposes, advantages and disadvantages? When shall we use which?
In this very simple example, do they work the same, correct?…
user3284469
20
votes
3 answers
Error 6046: Unable to generate function import return type of the store function
I have a scalar-valued function in my sql database.
I receive this error when importing this function into Entity Framework model:
Error 6046: Unable to generate function import return type of the store function 'GetContentByIdAndCul'.
The store…

Sayed Abolfazl Fatemi
- 3,678
- 3
- 36
- 48
20
votes
5 answers
How to create Daylight Savings time Start and End function in SQL Server
I need to create a function in SQL server that returns daylight savings time start datetime and daylight savings time end datetime.
I've come across a few examples on the web, however they all are using the 1st date of March and the 1st date of…

Amanda Brine
- 311
- 2
- 4
- 13
19
votes
2 answers
Why MySQL is giving error "Not allowed to return a result set from a function"?
I am trying to create a MySQL function using phpMyAdmin and getting this error.
#1415 - Not allowed to return a result set from a function
The function code is as below:
DELIMITER $$
CREATE FUNCTION get_binary_count(a INT, c INT)
RETURNS…

aslamdoctor
- 3,753
- 11
- 53
- 95
17
votes
8 answers
Why do SQL Server Scalar-valued functions get slower?
Why do Scalar-valued functions seem to cause queries to run cumulatively slower the more times in succession that they are used?
I have this table that was built with data purchased from a 3rd party.
I've trimmed out some stuff to make this post…

DBAndrew
- 6,860
- 2
- 20
- 17
17
votes
6 answers
Incompatible object type when create and alter a table value function in SQL
I'm getting the below error for the given function.
Msg 2010, Level 16, State 1, Procedure GetTableFromDelimitedValues, Line 2
Cannot perform alter on 'dbo.GetTableFromDelimitedValues' because it is an incompatible object type.
IF NOT EXISTS(SELECT…

ary
- 597
- 3
- 8
- 20
16
votes
4 answers
PostgreSQL function or stored procedure that outputs multiple columns?
Here is what I ideally want. Imagine that I have a table with the row A.
I want to do:
SELECT A, func(A) FROM table
and for the output to have say 4 columns.
Is there any way to do this? I have seen things on custom types or whatever that let you…

A Question Asker
- 3,339
- 7
- 31
- 39
15
votes
3 answers
SQL: Last_Value() returns wrong result (but First_Value() works fine)
I have a table in SQL Server 2012 as the snapshot shows:
Then I'm using Last_Value() and First Value to get AverageAmount of each EmpID for different YearMonth. The script is as follows:
SELECT A.EmpID,
First_Value(A.AverageAmount) OVER…

Echo
- 1,117
- 4
- 22
- 43
13
votes
3 answers
How to call a recursive function in sql server
I have a table as follows
cat_id Cat_Name Main_Cat_Id
1 veg null
2 main course 1
3 starter 1
4 Indian 2
5 mexican 2
6 tahi 3
7 chinese 3
8 nonveg null
9 …

Rhushikesh
- 3,630
- 8
- 45
- 82
13
votes
3 answers
SQL date format convert? [dd.mm.yy to YYYY-MM-DD]
is there mySQL function to convert a date from format dd.mm.yy to YYYY-MM-DD?
for example, 03.09.13 -> 2013-09-03.

user2216190
- 784
- 5
- 10
- 25
11
votes
3 answers
Registering a SQL function with JPA and Hibernate
I would like to know what's the best way to register a custom SQL function with JPA/Hibernate.
Do I have to go through extending the MysqlInnodb dialect or is there a better way?
Can anyone please provide code samples and pointers to relevant…

balteo
- 23,602
- 63
- 219
- 412
10
votes
4 answers
How do I create a SQL Server function to return an int?
I'm trying to create a SQL Function that tests whether a parameter starts with a certain term or contains the term, but doesn't start with it.
Basically, if the parameter starts with the term, the function returns a 0. Otherwise it returns a 1.
This…

DaveDev
- 41,155
- 72
- 223
- 385
10
votes
7 answers
Alter SQL Function Referenced by Computed Column
If you set up a table's column to be a computed column whose Formula calls a Function, it becomes a pain to change that underlying Function. With every change, you have to find every single column whose Formula that references the Function, remove…

colithium
- 10,269
- 5
- 42
- 57
10
votes
3 answers
Database Function VS Case Statement
Yesterday we got a scenario where had to get type of a db field and on base of that we had to write the description of the field. Like
Select ( Case DB_Type When 'I' Then 'Intermediate'
When 'P' Then 'Pending'
…

Usman Khalid
- 3,032
- 9
- 41
- 66