If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Create function problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-03-04, 09:09
atmosphere atmosphere is offline
Registered User
 
Join Date: Aug 2004
Posts: 19
Create function problem

Hi

i know this question is pretty trivial, but i am struggling on the create function command.
I want to create a function which takes in a column of datetimes and spits out a column of strings (some operations performed on the dates that are returned)

I have looked and looked but i cant seem to get the syntax down correctly.
Could someone PLEASE provide me with a template. Heres the sql code that will go in the function:

VARCHAR(DATE(t1)) CONCAT ' ' CONCAT
VARCHAR(CHAR(TIME(t1), JIS)) CONCAT '.' CONCAT
LTRIM(RTRIM(LEFT(VARCHAR(CHAR(MICROSECOND(t1))), 3))) CONCAT
REPEAT('0', 3 - LENGTH(LTRIM(RTRIM(LEFT(VARCHAR(CHAR(MICROSECOND(t 1))), 3)))))

Thank you
Reply With Quote
  #2 (permalink)  
Old 09-03-04, 09:32
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Try
CREATE FUNCTION Myschema.myudf(t1 timestamp)
RETURNS VARCHAR(75) LANGUAGE SQL DETERMINISTIC NO EXTERNAL ACTION CALLED ON NULL INPUT
BEGIN ATOMIC
DECLARE OUTTEXT VARCHAR(75);

SET OUTTEXT = VARCHAR(DATE(t1)) CONCAT ' ' CONCAT
VARCHAR(CHAR(TIME(t1), JIS)) CONCAT '.' CONCAT
LTRIM(RTRIM(LEFT(VARCHAR(CHAR(MICROSECOND(t1))), 3))) CONCAT
REPEAT('0', 3 - LENGTH(LTRIM(RTRIM(LEFT(VARCHAR(CHAR(MICROSECOND(t 1))), 3)))));

RETURN OUTTEXT;
END

HTH

Andy
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On