Questions tagged [sql-function]

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.

908 questions
3
votes
8 answers

MySQL Function to add a number of working days to a DATETIME

I need a MySQL Function that will allow me to pass a number of working days (Monday - Friday) and a start DATE or DATETIME (doesn't matter for my implementation), and have it return a new DATE or DATETIME that many work days in the future. Example:…
Jason Bristol
  • 401
  • 1
  • 5
  • 19
3
votes
3 answers

Performance of Sql subqueries\functions

I am currently working on a particularly complex use-case. Simplifying below :) First, a client record has a many-to-one relationship with a collection of services, that is, a single client may have multiple services associated with it. Within my…
johnny g
  • 3,533
  • 1
  • 25
  • 40
3
votes
1 answer

SQL function returns correctly but shows error in Management Studio

I have this function, which although it returns the value correctly, shows an error in the Management Console with the squiggly red underline: Cannot find either column dbo or the user-defined function or aggregate The reason this is a problem is…
greener
  • 4,989
  • 13
  • 52
  • 93
3
votes
2 answers

How to ceil decimal point?

As round will round either up or down, it can't be used in my case all though you can control the decimal point. The problem is floor and ceil does not allow to control the decimal point, in case of floor you can use truncate which will…
eric.itzhak
  • 15,752
  • 26
  • 89
  • 142
3
votes
3 answers

Java Equivalent of Oracle translate

Is there any equivalent string function or library in java that behaves the way oracle translate function does? In oracle I can do this: select translate( '23423k!(dfgd){sdf};', '(){}k!', '{}()' ) from dual; to get this: 23423{dfgd}(sdf); But…
johan.i.zahri
  • 316
  • 6
  • 18
3
votes
4 answers

Convert stored procedure to table-valued query

I have this procedure ALTER PROCEDURE [dbo].GetHerdByUserProc(@user int) As begin Declare @GroupId uniqueidentifier, @UserTrade bit Set @GroupId = (select tbUser.group_id from tbUser where Userid =…
3
votes
1 answer

Executing Oracle Functions using Spring jdbc

I am trying to execute Oracle function using Spring jdbc. But I am getting below error CallableStatementCallback; bad SQL grammar [{? = call RATELIMIT_OWN.GET_LOGS(?, ?)}]; nested exception is java.sql.SQLException: ORA-06550: line 1, column 24:…
RaceBase
  • 18,428
  • 47
  • 141
  • 202
3
votes
2 answers

MSSQL use of Functions indexing, and performance

In my past experience, I've always used functions in simple cases where I need to select a dataset, without a lot of complex logic, and I need to also pass a parameter. I've recently been informed that I should avoid using functions in MSSQL at all…
wakurth
  • 1,644
  • 1
  • 23
  • 39
2
votes
3 answers

Insert current row number into SQL Server table

I have the following table in SQL Server: CREATE TABLE [dbo].[tblTempPo]( [TempPoID] [int] IDENTITY(1,1) NOT NULL, [guid] AS ([dbo].[GetIdentity]()), [Qty] [int] NULL, [MobileBrandID] [int] NULL, [MobileID] [int] NULL ) I need…
chamara
  • 12,649
  • 32
  • 134
  • 210
2
votes
1 answer

Linq PredicateBuilder

public static IQueryable FilterData(string Filter, Repository dc) { IQueryable data = null; var predicate = PredicateBuilder.True(); Filter =…
user805661
  • 51
  • 1
  • 3
2
votes
1 answer

Generate a sequence of square numbers till 10

How to generate a sequence of SQUARE numbers till 10 in MYSQL? (1^2,2^2, etc) I was only able to generate a numerical sequence from 1 to 10. WITH RECURSIVE cte (n) AS ( SELECT 1 UNION ALL SELECT (n + 1) FROM cte WHERE n < 10 ) SELECT n FROM…
Mouse12328
  • 23
  • 3
2
votes
1 answer

Alternative to nesting regex replace in PostgreSQL functions?

Right now, I have a view with a mess of common, conditional string replacement and substitutions for an open text field - in this example, regional classification. (Please ignore the accuracy of geography, I'm just working with historical standard…
ghostrobot
  • 43
  • 4
2
votes
1 answer

How to order by max(a,b) in SQL?

Consider the following table: id a b -------------- 1 5 1 2 2 3 3 4 2 4 3 6 5 0 1 6 2 2 I would like to order it by max(a,b) in descending order, so that the result will be: id a …
Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
2
votes
1 answer

Re-use a hardcoded value in multiple function calls in PostgreSQL query

I have some functions in PostgreSQL 9.0 that return table results. The idea behind these is to return the data as it was at a certain time, eg. CREATE FUNCTION person_asof(effective_time timestamp with time zone) RETURNS SETOF person ... CREATE…
EMP
  • 59,148
  • 53
  • 164
  • 220
2
votes
1 answer

How can I create a Postgres 11 trigger function which inserts a new row in table 'b' upon insert or update to table 'a'?

I'm running Postgres 11 on RDS. I'm trying to create a simple trigger function to insert records into table 'test_alias' whenever a row is inserted into table 'test_values'. I have the following tables: CREATE TABLE the_schema.test_values ( id…
Mister October
  • 165
  • 1
  • 9