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
0
votes
1 answer
Column 'dbo.Class2.ID' is invalid in the select list because it is not contained in either an aggregate function or the group by claus
I am trying to create a Sql function,Where a list of students is fetched by specifying their class status.I could create a function to retrieve such an information for a single user,But when i tried to get a list for all of them i get this error.…

Hossein
- 24,202
- 35
- 119
- 224
0
votes
1 answer
SQL Server How to pass a list of ids from sproc to function
Unlike most situations that I've found on the internet when people need to pass a list of id's to a sproc from an application like c# then split the id's up so they can be used in the WHERE clause like WHERE IN (4,5,6,7,7,8)
I need to call a sql…

Vinyl Windows
- 503
- 1
- 7
- 19
0
votes
2 answers
How to create text files of database rows?
I have a database table with a column named File Content, and many rows. What I need is to create a text file for each row of File Content column.
Example:
Sr. File Name File Content
1. FN1 Hello
2. FN2 …

Azeem Akram
- 223
- 6
- 9
- 21
-1
votes
1 answer
Why is the column value not persisting after Postgres function triggers after update?
I have a table called Projects where I need to set a certain column value after an update is executed and the record matches certain conditions. The function triggers correctly and there are no errors but the updated column value does not…

Samuel Alito
- 15
- 2
-1
votes
1 answer
Function is not working with varchar records
I have a function that in theory will give the country name as output when the input is the city name:
CREATE OR REPLACE FUNCTION public.country_by_city(city varchar, OUT Country varchar)
RETURNS varchar
LANGUAGE SQL AS
$function$
SELECT…

lowercase male
- 11
- 4
-1
votes
1 answer
How can i combine multiple functions into one in postgresql?
I wrote a series of functions updating a progress column in my project, I wonder if this can be combined into a single function. I tried it, using SELECT * FROM schema.table; IF, ELSE IF ... THEN UPDATE column SET progress = xx however all i got was…

kimmi-0
- 1
- 1
-1
votes
2 answers
Error while trying to return one column from SQL Server function
I have a function in SQL Server with a select statement and I want to return one row calculated inside the select statement - ORDER_VALUE_ADJUSTED.
CREATE FUNCTION order_value
(@date DATE,
@client VARCHAR(50),
@order_number…

Leonardo
- 39
- 5
-1
votes
1 answer
PgSQL function returning table and extra data computed in process
In PgSQL I make huge select, and then I want count it's size and apply some extra filters.
execute it twice sound dumm,
so I wrapped it in function
and then "cache" it and return union of filtered table and extra row at the end where in "id" column…

vanilla
- 43
- 1
- 5
-1
votes
1 answer
ERROR: syntax error at or near "declare" LINE 5: declare @b_result bit ^
This is a working function in SQL Server 2014 Express
CREATE FUNCTION [dbo].[Func_Account_FollowingCustomer]
(@AccountNumber NVARCHAR(20))
RETURNS BIT
AS
BEGIN
DECLARE @bResult BIT
IF (SELECT COUNT(AccountNumber) FROM dbo.Account…

Vy Do
- 46,709
- 59
- 215
- 313
-1
votes
1 answer
Part Id 3900 take wrong technology id as 7 and it must Be 2 because Feature Name and Value Exist?
I work on sql server 2017 I have table #partsfeature already exist as below
create table #partsfeature
(
PartId int,
FeatureName varchar(300),
FeatureValue varchar(300),
TechnologyId int
)
insert into…

ahmed barbary
- 628
- 6
- 21
-1
votes
2 answers
How would I solve this function assignment in PL/SQL?
So the assignments goes like this:
Make a PL/SQL function that takes in 2 parameters (exmaple p1 and p2). The function then has to calculate the sum of all the numbers between the range of p1 and p2. P1 doesn't always have to be smaller than P2.
The…
user17388101
-1
votes
1 answer
Replacing all 0s with Nulls in a table
Is there a way to replace all 0s with a null for all the columns of a table ? I know how to do it for single column, I am searching for something like dynamic query for all the columns.

Shadow
- 21
- 5
-1
votes
1 answer
PostgreSQL save table columns results into variables
I have this function:
DECLARE
_first_name text;
_last_name text;
BEGIN
SELECT
emp.first_name INTO _first_name,
emp.last_name INTO _last_name,
FROM employee emp LIMIT 1
END;
(I simplified the function to eliminate the information…

john2994
- 393
- 1
- 3
- 15
-1
votes
2 answers
Return JSON in Postgres
I have created a function in postgres that returns json.
The function is used in an API and returns this:
[
{
"jobfeed_beroepen_list": [
{
"profession_code": 3674,
"profession_descr": "Manusje…

Arjan Ruis
- 3
- 1
-1
votes
1 answer
Expression of non boolean type specified on context where condition is expected near ')'
I work with SQL Server 2012 I get this error:
Expression of non boolean type specified on context where condition is expected near ')'
I think this is because it can't handle 'N/A' OR Null or Text.
How to modify dynamic SQL to accept N/A AND NULL…

ahmed barbary
- 628
- 6
- 21