functions
functions
(OP)
Can we define new functions ( similar to built-in , for example - trim ) for use in select statement.
If so can I have an example.
Thanks in advance
Sri
If so can I have an example.
Thanks in advance
Sri
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS Contact USThanks. We have received your request and will respond promptly. Come Join Us!Are you a
Computer / IT professional? Join Tek-Tips Forums!
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail. Posting Guidelines |
|
Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.
Here's Why Members Love Tek-Tips Forums:
Register now while it's still free!
Already a member? Close this window and log in.
RE: functions
You can create stored procedures and call them from SQL:
Here's a sample stored procedure:
-- This procedure returns the number of seconds between datetime dt1 and dt2.
-- change to character first because the interval to integer conversion
-- fails. Ed Schaefer 09/23/98
CREATE PROCEDURE int_in_sec(dt1 DATETIME YEAR TO SECOND, dt2 DATETIME YEAR
TO SECOND) RETURNING INTEGER;
DEFINE int_sec INTERVAL SECOND(9) TO SECOND;
DEFINE xchar CHAR(20);
DEFINE xint INTEGER;
LET int_sec = dt2 - dt1; -- get the interval
LET xchar = int_sec; -- change to char
LET xint = xchar; -- change to integer
RETURN xint;
END PROCEDURE;
Here's a sample table:
create table sample_table
(
dt1 datetime year to second,
dt2 datetime year to second
);
with sample data:
insert into sample_table values ("2002-02-28 16:00:23", "2002-02-28 17:00:24")
and with the sample select:
select int_in_sec(dt1, dt2) from sample_table
returns the value: 3601
Regards,
Ed
Schaefer