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
-3
votes
2 answers
Match and merge when comparing data in 4 tables
I have a requirement to create SQL Server user defined function/SP (either normal or table valued function) which has the below requirements:
The data across 4 tables (Table_A, Table_B, Table_C, Table_D) should be matched based on fix attributes…

Nitesh
- 5
- 2
-3
votes
2 answers
In SQL server management if not null then replace the value with one
ALTER FUNCTION [dbo].[Get_CGPA] (@s1 DECIMAL(20, 2), @s2 DECIMAL(20, 2), @s3 DECIMAL(20, 2), @s4 DECIMAL(20, 2), @s5 DECIMAL(20, 2), @s6 DECIMAL(20, 2), @s7 DECIMAL(20, 2), @s8 DECIMAL(20, 2)) RETURNS DECIMAL(20, 2) AS
BEGIN
DECLARE @cgpa…

Sharon Saji
- 3
- 2
-3
votes
3 answers
SQL Server: Run separate CTE for each record without cursor or function
Given table A with a column LocationID and many records,
Is it possible to fully run a CTE for each record, without using a cursor (while fetch loop) or function (via cross apply)?
I can't run a CTE from the table A because the CTE will go deep…

igorjrr
- 790
- 1
- 11
- 22
-3
votes
1 answer
Append string in where clause in SQL
I have a function in SQL that returns where clause result like this
CREATE FUNCTION dwd.GetSearchCriteria
(
@pValue NVARCHAR(50),
@pCriteriaOption NVARCHAR(3)
)
RETURNS varchar(30)
AS
BEGIN
declare
@WHERE varchar(2000)
IF(@pValue IS NOT…

Ghazanfar Khan
- 3,648
- 8
- 44
- 89
-4
votes
1 answer
Function to select rows from multiple tables based on conditions from different tables
Can anyone please help with this query?
I’m using SQL server 2008 . Objective is to select rows from multiple tables based on condition and values from different tables .
I have table1, table2, tableN with columns as ID,ColumnName,ColumnValue .…

AHS
- 87
- 1
- 9
-4
votes
4 answers
How to get data without duplicates for two columns from the same table
select DISTINCT column1, (select DISTINCT column2 from table1 ) from table1
I want both column1 and column2 value without duplicate

Ratheesh krishna
- 17
- 4
-4
votes
2 answers
SQL: Is it possible to block a table insert just prior to the completion of a transaction?
TL;DR: My real question is in the title, is it possible to block a table insert just prior to the completion of a transaction, that is, only concerning the data as it would be right before the transaction would be committed?
UPDATE: What procedes is…

user420667
- 6,552
- 15
- 51
- 83
-5
votes
1 answer
Using multiple IF ELSE in A multi-statement TVF Sql Server
How can I use IF ELSE statements inside A multi-statement TVF ? My Cide goes like this
CREATE FUNCTION Production.ms_tvf_ProductCostDifference
(
@ID INT ,
)
RETURNS @retCostDifference TABLE
(
ProductId INT ,
CostDifference…

user2490024
- 75
- 1
- 2
- 7