Questions tagged [user-defined-functions]

A function provided by the user of a program or an environment most often for spreadsheet type applications or database applications. Use [custom-functions-excel] for Excel and [custom-function] for Google sheets. Specify a programming language tag as well: [google-apps-script], [javascript], [sql], [tsql], etc. as well as a tag for the application: [excel], [google-spreadsheet], [sql-server] etc.

In the context of a programming language or an environment, a User Defined Function (UDF) is a function that is created by a user to perform a specific task (as opposed to a function that is intrinsic to the environment, built into the programming language or environment).

Spreadsheet applications like Excel and Google Sheets calls these "custom functions".

Microsoft also uses the term User Defined Functions with . The tag may also be applicable. See What is the need for user-defined functions in SQL Server?

Use:

4875 questions
1
vote
9 answers

The pros and cons of "Shadow IT" in software development

Recently we’ve seen the emergence of so-called “Shadow IT” within many organisations. If you’re not already familiar with the term, it refers to those who manage to dodge the usual IT governance by means such as using thumb drives to share files or…
1
vote
5 answers

Help with slow UDF in SQL Server 2005

I have a table of dates call [BadDates], it has just one column where every record is a date to exclude. I have a UDF as follows: CREATE FUNCTION [dbo].[udf_GetDateInBusinessDays] ( @StartDate datetime, --Start Date @NumberDays int …
Dustin Laine
  • 37,935
  • 10
  • 86
  • 125
1
vote
2 answers

MySQL Split String Function SPLIT_STR does not work with LEFT JOIN. Any issue?

Create MySQL Split String Function SPLIT_STR fedecarg.com/.../mysql-split-string-function/ CREATE FUNCTION SPLIT_STR( x VARCHAR(255), delim VARCHAR(12), pos INT ) RETURNS VARCHAR(255) RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos), …
Binyamin
  • 7,493
  • 10
  • 60
  • 82
1
vote
2 answers

Is it possible to add a check constraint that calls a user defined function in a different database?

I'm trying to add a user defined function that actually calls the SQL# CLR function RegEx_IsMatch to a column, but I get this error: A user-defined function name cannot be prefixed with a database name in this context. But if the function is in a…
1
vote
4 answers

Calling a function from within a select statement - SQL

I have the following statement: SELECT CASE WHEN (1 = 1) THEN 10 ELSE dbo.at_Test_Function(5) END AS Result I just want to confirm that in this case the function wont be executed? My reason for asking is that the function is particularly slow and…
vdh_ant
  • 12,720
  • 13
  • 66
  • 86
1
vote
4 answers

C+ program involving functions...Please help me

I am having a hard time with two functions. Here are the project instructions: Assignment: Write a program which keeps track of the number of roaches in two adjacent houses for a number of weeks. The count of the roaches in the houses will be…
1
vote
1 answer

variable table or column names in a function

I'm trying to search all tables and columns in a database, a la here. The suggested technique is to construct SQL query strings and then EXEC them. This works well, as a stored procedure. (Another example of variable table/column names is here.…
LarsH
  • 27,481
  • 8
  • 94
  • 152
1
vote
3 answers

Sql Server Joining Result sets from stored procedures

Here is the problem. I have a stored procedure that transforms normalized data into a standard dataset. I need to report on some data which consists of a view, and two data sets from the stored procedure with different parameters being submitted to…
1
vote
3 answers

CLR UDF returning Varbinary(MAX)

Is it possible for a SQL CLR User-Defined Function to return the data type varbinary(MAX)? In the documentation it mentions: "The input parameters and the type returned from a scalar-valued function can be any of the scalar data types supported by…
Sam Schutte
  • 6,666
  • 6
  • 44
  • 54
1
vote
1 answer

Weird foreach + user-defined function behavior in Makefiles

I have the following Makefile: X=a.jar b.jar c.jar Y=/var/tmp/abc/a.jar /var/tmp/abc/b.jar /var/tmp/abc/c.jar all: $(addprefix /var/tmp/abc/tmp/, $(X)) define AddRule dst=$1 src=$2 /var/tmp/abc/tmp/$(dst): $(src) @echo $$@ @echo…
1
vote
1 answer

Using Dynamic SQL in User Defined Function to return string (not modify data)

Our document storage application has a unique database for each of our clients which are almost identical to each other, but one table DocumentIndexes is unique for each client and can have any number of columns and types. I am trying to create a…
bigmac
  • 2,553
  • 6
  • 38
  • 61
1
vote
1 answer

How do you compile a UDF in Cloudera's distribution of Hadoop+Pig

I am running Cloudera's VM (CH3). I've copied a simple UDF in my text editor, but I don't know how to compile it in order to be able to call it in a script. The Pig UDF manual http://pig.apache.org/docs/r0.7.0/udf.html says to build pig.jar, however…
1
vote
1 answer

Problems setting up an SQL User-Defined Function in MySQL using the Java Language

I have had quite some difficulty trying to make a User Defined Function (UDF) in Java for my MySQL Server. I was hoping I could ask for some help on this subject. Here is what I have done so far: I have followed the instructions on a Planet MySQL…
Kaushik Shankar
  • 5,491
  • 4
  • 30
  • 36
1
vote
1 answer

UDF in C# that updates a table (dividing all data with result of query)

Is there a way to divide each data of a table (all columns and rows) by select count(*) from table; so for example table a1 a2 a3 a4 ------------------- 438 498 3625 3645 500 291 5000 2351 233 263 1298 1687 198 117…
edgarmtze
  • 24,683
  • 80
  • 235
  • 386
1
vote
1 answer

Passing select statement as parameter to scalar function in SQL

I have scalar function which takes an integer as argument and return an integer too. I was trying to use this function by passing a parameter as a select statement which looks like : select dbo.scalarFunc(select si.ID from table1 si where version =…
Ratan
  • 863
  • 5
  • 12
  • 28