user-defined-functions

SQL Scalar function element not recognized in TSQL program

I have an input db2 table with two elements: loan_number, debt_to_income; this table's name is #Input_Table. I am trying to run a test the function by running a SQL program against this table. The problem is that the function's element is not being recognized in the SQL program for some reason, maybe I have been looking at to long? I nee...

Try-Catch in User Defined Function?

I'm trying to write a UDF to translate a string that is either a guid or a project code associated with that guid into the guid: CREATE FUNCTION fn_user_GetProjectID ( @Project nvarchar(50) ) RETURNS uniqueidentifier AS BEGIN declare @ProjectID uniqueidentifier BEGIN TRY set @ProjectID = cast(@Project as uniqueide...

Exploding a string and looping through an array in MySQL outside another language

I'm creating a MySQL UDF (User Defined Function) to capitalise the first letter of every word. This is what I have so far: drop function if exists upperfirst; create function upperfirst (s varchar(255)) returns varchar(255) deterministic return concat(ucase(mid(lower(s),1,1)),mid(lower(s),2)); This is working pretty well so ...

SQL function returns wrong value

I have a function that takes 2 parameters: @iEmployeeID and @dDate. It's purpose is to find a budget rate for the given parameters. In other words, it should find the largest date being smaller or equal to the @dDate argument, and return the rate that corresponds. Budget rates are: Start Rate ------- ----- 01-01-2008 6...

SQL function, extract numbers before -

Hi, i'm playing around with building a sql function that will extract numbers from a title, which is what the following code below does. Although, i want to modify this function to parse numbers into sections. For example: Current Data in title field: QW 1 RT 309-23-1 QW 1 RT 29-1 QW 1 RT 750-1 QW RT 750-1 Temp tables created once f...

header files in C

how to create user defined header files in C step by step please including the compiling process as well :) SOLVED TY ALL ...

continuously execute an emacs lisp function

Is there a way to trigger the execution of an emacs lisp function other than M-x myfun? I would like to have the function re-called every time the buffer is changed. Background: I have a table of numbers with some mistakes. The table has column totals and other features which can be used to identify the mistakes. My elisp function highl...

Sql string manipulation within stored procedure

Hi, I have a field which contains article titles. I need to create friendly or pretty url's out of the article titles. I need help manipulating the string with SQL. This has to be done within a stored procedure or function. The requirements: The only characters allowed are lowercase letters and numbers (a-z and 0-9) All spaces need to...

Create a concatenation function in SQL

Hi, Suppose I have a table a with one column b and three rows(1,2,3), I would like to create a function that will return '1,2,3' that would be called like this : SELECT FUNC(f), ... FROM ... In other words, I have a linked table that have more than one rows linked to each rows of the first table and would like to concatenate the conten...

MySQL does not support recursive functions? why? since when?

I've written a stored FUNCTION that calls itself, recursively. However when I run it in a query I get this shameless error: Error: 1424 SQLSTATE: HY000 (ER_SP_NO_RECURSION) Message: Recursive stored functions and triggers are not allowed. "Not allowed"? Right. Why don't we just disable WHILE loops also, while we're at it? ...

In R, how can an element of a vector of functions be selected and applied?

I have an R question--I want to make a vector of functions, and then be able to call one of the functions by name. However, when I use this name, I want to use a tag which maps to that name, so that I can chance which name I use without having to change the code. For example: #define tag tag<-"F" #define functions f <- function(x) prin...

Mysql query with user-defined-function - why function was called twice?

I have a 1:1 relation between tables Entity and Contact (that corresponds to object 's inherirance). fn_match(id) is UDF which returns boolean and returns true if record matches some special criteria (additional queries inside function). That's a query: select * from Entity a inner join Contact b on a.id = b.id where fn_match(a.i) It ...

MySQL User Defined Function for Latitude Longitude Syntax

I have created a MySQL function to determine if a set of latitude and longitude coordinates are within a certain range of another set of latitude and longitude coordinates. However, the function is giving me a syntax error so I cannot test to see if it is working properly. Any help figuring out what is causing the error would be greatly ...

Confused about return statement in user defined function

hi there, i have few question regarding the return statement. a) is it compulsory to define a return statement in a user defined function.? b) is it still valid if i just define a return statement without any parameter? will it return the null value? c) is the following function valid? function admin_credential($password = 0, $email...

hibernate : howto order by custom (user-defined) function in PostgreSQL 8.4

We have a Family Hibernate Entity. This entity has(among others) 4 booleans properties. When retrieving the Families from the Postgres 8.4 DB, it is required that the List of families be ordered by sum of the boolean properties. There are 2 other fields in the order by criterion. Eg select fam.a, fam.b, fam.c, fam.d, fam.e from family...

I'm getting a "conflicting types" error in C

I'm currently working on a program for a C course in which I have to output the area of a shape. Here is a function for a rectangle's area that I have in my program: double rectangle() // calculate area of rectangle { double length, width; printf("\nEnter length and width of rectangle: "); scanf("%g %g\n", &length, &width)...

MySQL returning results from one table based on data in another table

Before delving into the issue, first I will explain the situation. I have two tables such as the following: USERS TABLE user_id username firstName lastName GROUPS TABLE user_id group_id I want to retrieve all users who's first name is LIKE '%foo%' and who is a part of a group with group_id = 'givengid' So, the query would like somet...

PostgreSQL+PostGIS function that gives angular seperation for a pair of (lat,long) points.

I wrote the following code (after spending a few hours trying to get the quoting correct): CREATE FUNCTION ast3angsep(double precision, double precision, double precision, double precision) RETURNS double precision AS $$ SELECT ST_Distance( ST_GeographyFromText('SRID=4326;POINT('||$1||' '||$2||')'), ST_GeographyFromText('SRID=4326;POINT...

SQL Query: Each GROUP BY expression must contain at least one column that is not an outer reference.

Getting this error: Each GROUP BY expression must contain at least one column that is not an outer reference. RowId ErrorDatetime ErrorNum ErrorMessage 824 2010-09-24 08:01:42.000 9001 Account 55 not found 823 2010-09-24 08:00:56.000 9001 Account 22222222222 not found 822 2010-09-24 05:06:27.000 ...

How to use a recursive function to update a table?

This is a follow-up from this question. Functions are not allowed to write to the database, but what if I wanted to update a record every time a function was called, specifically a recursive function? Currently, I have a function that takes an ID and returns a float. I'd like to update a table using the given ID and the returned float....