Posted: Thu Oct 06, 2005 6:53 am Post subject: Padding a field
Centurion
Joined: 09 Oct 2002 Posts: 100 Location: Kansas City
One of the common things I am working on it Justifying and Padding within eSQL. There are a few ways to do this there are four examples below. For the example I'm using right justify left pad with zeros.
<InputNumber>123456</InputNumber>
A.
Code:
DECLARE InputNumber CHAR;
SET InputNumber = CAST(InputBody.XML.InputNumber AS CHAR);
WHILE LENGTH(InputNumber) < 10 DO
SET InputNumber = '0' || InputNumber;
END WHILE;
B.
Code:
DECLARE InputNumber CHAR;
SET InputNumber = SUBSTRING('0000000000' FROM 1 FOR (10-LENGTH(InputNumber))) || CAST(InputBody.InputNumber AS CHAR);
C.
Code:
DECLARE InputInteger INT;
DECLARE InputNumber CHAR;
SET InputInteger = 10000000000 + InputBody.InputNumber;
SET InputNumber = SUBSTRING(CAST(InputInteger AS CHAR) FROM 2 FOR 10);
D.
Code:
SET InputNumber = RIGHT('0000000000' || CAST(InputBody.InputNumber AS CHAR),10)
Does anyone know a best practice for which way is faster/more reliable or is there another way.
Joined: 14 Apr 2003 Posts: 125 Location: Foxboro, MA
There is an OVERLAY function which which can accomplish this. Refer to the esql manual for exact syntax. _________________ IBM Certified Specialist: MQSeries
IBM Certified Specalist: Websphere MQ Integrator
Joined: 09 Oct 2002 Posts: 100 Location: Kansas City
E.
Code:
DECLARE InputLength INT;
DECLARE InputNumber CHAR;
SET InputLength = LENGTH(InputRoot.InputNumber);
SET InputNumber = OVERLAY('0000000000' PLACING InputRoot.InputNumber FROM (10-InputLength) FOR InputLength);
Joined: 14 Apr 2003 Posts: 125 Location: Foxboro, MA
What are you doing with InputNumber? Is that going to be mapped to a field that is defined in a message set? _________________ IBM Certified Specialist: MQSeries
IBM Certified Specalist: Websphere MQ Integrator
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum