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
-1
votes
3 answers
What are the differences between `YEAR(OrderDate)` and `DATEPART(year,OrderDate)`
Assume OrderDate is a date. What are the differences between YEAR(OrderDate) and DATEPART(year,OrderDate) (or DATEPART(yyyy,OrderDate) or DATEPART(yy,OrderDate) )? Thanks.

Tim
- 1
- 141
- 372
- 590
-1
votes
1 answer
mysql coupled OR statement
I'm trying to do a coupled OR statement
select * from table where cat = "x" OR (cat = "y" AND rand()<=0.25);
So I would like to select all items with cat = x or cat = y, but only 25% of y. The statement above gives med 25% of both x and y.
How can…

12344343243
- 43
- 1
- 10
-1
votes
1 answer
Group by highest/MAX value and calculate difference
This is MYSQL/ SQL running against data on Oracle server. I have a SQL table that stores data as follows:
{IMPORTID Created IMPORTREQUESTID STARTDATE ENDDATE
1156 04/21/2017 (12 AM) 63833 4/23/2017 18:18 4/23/2017…

Reza Taksokhan
- 1
- 1
- 4
-1
votes
4 answers
How to replace 0 and 1 in SQL Server 2012
I have a rugby database + player table. In the player table I have performance and I want to represent the performance as
0 = low
1 = medium
2 = high
I don't know what datatype the column should be. And what is the formula or function to do…

Khaled Mahmod
- 7
- 1
- 2
-1
votes
1 answer
cannot return a table grouped by variables in MS SQL server Management studio
I created the following function:
CREATE FUNCTION categorize (
@id VARCHAR(5),
@var1_low INT,
@var1_high INT,
@var2_low DECIMAL(18,6),
@var2_high DECIMAL(18,6)
)
RETURNS TABLE
AS RETURN
(SELECT
year,
…

Jenny Shu
- 47
- 2
- 4
- 12
-1
votes
1 answer
Using MAX function in MySQL query
I have a SQL query where I would like to select rows from lesson table where idLesson column is greater than MAX from idLesson of attendance table. How can I correct this query?
SELECT student.userid, lessons.idLesson, student.fee,…

M. Namiz
- 99
- 8
-1
votes
1 answer
Cannot find an error in my SQL function
I have a simple function. It has not finished yet, but while doing intermediate check, I'm getting an error saying Invalid column name 'chksum1'
ALTER FUNCTION [dbo].[fnMidCheckSum]
(
@MID varchar(16)
)
RETURNS int
AS
BEGIN
DECLARE
…

gene
- 2,098
- 7
- 40
- 98
-1
votes
1 answer
SQL - Can I have a Group By clause after a nestled Select?
For example:
Select max(date)
From table A
Where max(date) < any (select..
...)
Group By Book_Name,Client_Name
So the max(date) field could be compared to the Nestled Select return, as if the grouping of the greater Select…

Mr Guliarte
- 739
- 1
- 10
- 27
-1
votes
1 answer
MongoDB CRUD functions using parameters
How to write custom functions in MongoDB for performing CRUD operations and with parameters (1 to 'N' fields like stored procedures in SQL)?

Mahesh Kumar
- 1
- 1
-1
votes
4 answers
How can I parse special characters in T SQL
I'm writing an SQL Server function which should parse the input string and apply some function on it,
some characters in the input are " and '. How can I recognize them in function?
Declare @Str varchar(300)
Declare @CurrentChar char --("A" OR…

Sara N
- 1,079
- 5
- 17
- 45
-1
votes
2 answers
Adding NULL to an integer to get the integer result in SQL server
I have say a table, the columns of which will contain integer value but i am not sure if they may contain NULL too. Now lets say I want to add the integers, (along with any NULL) to get the result as an integer even when any column in between is…

vstandsforvinay
- 138
- 1
- 11
-1
votes
2 answers
TSQL: Using parameter with tablename in function
Using SQL Server 2014...
I'm trying to convert this code to be used in a function...
SET @sqlCommand = N'SELECT @text = ' + @fieldname + ' FROM ' + @tablename +' WHERE ID=''' + CONVERT(NVARCHAR(200), @ID) + ''''
EXECUTE sp_executesql...
...but…

MojoDK
- 4,410
- 10
- 42
- 80
-1
votes
1 answer
Got error like this (Php & mysql)
This is my sql function
CREATE FUNCTION returnPrice(price int,member int)
RETURNS INT
BEGIN
RETURN(price*member);
END;
And this is my php code
$res1= "CALL returnPrice('$cost','$team_member')";
$rs1 = mysqli_query($con,$res1);
$row1=…
-1
votes
1 answer
To String Conversion while doing Join in LINQ
I am using LINQ query to fetch the data from database and also doing joins in the LINQ query as,
(
from accountTransaction in AccountTransactions
join xlkpQualifier in Enumerations on
accountTransaction.LkpQualifier.ToString() equals…

Rahul
- 2,309
- 6
- 33
- 60
-1
votes
2 answers
What are sql function possible positions in sql statement?
I am looking for all the possible positions in a sql statement that a sql function can be called. It is my first time to use sql functions and in my code I need to detect whether users' input contains sql function, if so, the input is not valid.
The…

Cherry Wu
- 3,844
- 9
- 43
- 63