ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Test Data Type in ESQL?

Post new topic  Reply to topic
 Test Data Type in ESQL? « View previous topic :: View next topic » 
Author Message
NiceGuy
PostPosted: Thu Sep 16, 2010 9:55 am    Post subject: Test Data Type in ESQL? Reply with quote

Apprentice

Joined: 11 Jun 2009
Posts: 37

Hi community,

I have a quick question:

Does anybody know if (or simply a way) to test if a passed CHARACTER can be CAST to a INTEGER?

Allow me to provide a watered down example:
Code:

DECLARE nInt INTEGER;
DECLARE cString CHARACTER 'Net30';   
DECLARE cNumber CHARACTER '30';

-- First Example
SET nInt = CAST(cString AS INTEGER);  -- Fails/Exception

-- Second Example
SET nInt = CAST(cNumber AS INTEGER)   -- Okay



The idea is I am not certain what the passed variable will hold prior
to casting.

Thanks again for your time.
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Sep 16, 2010 10:02 am    Post subject: Re: Test Data Type in ESQL? Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

NiceGuy wrote:
Does anybody know if (or simply a way) to test if a passed CHARACTER can be CAST to a INTEGER?


- CAST with an impossible DEFAULT and test for the default
- CAST with a reasonable DEFAULT and continue processing
- TRANSLATE all the non-numerics out and see if it still has LENGTH
- TRANSLATE all the non-numerics out and CAST it with a DEFAULT

Other, possibly better methods are undoubtably possible.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
NiceGuy
PostPosted: Thu Sep 16, 2010 12:52 pm    Post subject: Reply with quote

Apprentice

Joined: 11 Jun 2009
Posts: 37

Hi Thanks for the reply,

Vitor writes ...
Quote:

TRANSLATE all the non-numerics out and see if it still has LENGTH


I had a feeling that suggestion may come up.

If I were to take this approach, is there an easy way to do this? What I
mean is if I were to use the TRANSLATE function, is there a quick and
easy way to supply all non-numeric characters?

For example:
Code:

SET test = TRANSLATE(aVariable, 'a-zA-Z', '');
 


I realize this will not work, but provided as a means to help explain
myself.

Thank-you immensely for you time.
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Sep 16, 2010 1:02 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

NiceGuy wrote:
If I were to take this approach, is there an easy way to do this? What I
mean is if I were to use the TRANSLATE function, is there a quick and
easy way to supply all non-numeric characters?

For example:
Code:

SET test = TRANSLATE(aVariable, 'a-zA-Z', '');
 


I realize this will not work, but provided as a means to help explain
myself.


What about something like this:

Code:

CREATE FUNCTION fOnlyNumbers(IN source CHARACTER) RETURNS CHARACTER
BEGIN
        DECLARE cTemp CHARACTER
       SET cTemp=TRANSLATE(source,'0123456789','');
      RETURN TRANSLATE(source,cTemp,'');
END;


Less typing.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Test Data Type in ESQL?
Jump to:  



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
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.