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 » How to get next alphabet char ?

Post new topic  Reply to topic
 How to get next alphabet char ? « View previous topic :: View next topic » 
Author Message
Ramphart
PostPosted: Fri Sep 10, 2004 1:59 am    Post subject: How to get next alphabet char ? Reply with quote

Disciple

Joined: 21 Jul 2004
Posts: 150
Location: South Africa, JHB

I'm looking for a function to give me the next char in the alphabet

e.g. function('A') must return 'B'
e.g. function('X') must return 'Y'
e.g. function('Z') must return 'A'

Is there a builtin SQL function that can do this? If not, any suggestion on how i write one to easily achieve this?

This is what I do for now:
IF value = 'A' THEN SET value = 'B'; ELSE IF
value = 'B' THEN SET value = 'C'; ELSE IF
value = 'C' THEN SET value = 'D; ELSE IF
--and so on ...
value = 'Y' THEN SET value = 'Z'; ELSE IF
value = 'Z' THEN SET value = 'A';
END IF; END IF;
END IF; END IF;
END IF;

Ramo
_________________
Applications Architect
Back to top
View user's profile Send private message
romudd
PostPosted: Fri Sep 10, 2004 5:16 am    Post subject: Reply with quote

Apprentice

Joined: 12 Aug 2003
Posts: 31
Location: Sao Paulo - Brazil

This may be done by incrementing the ASCII code for the letter. You can define a function for this. I made an example, improve it as you wish:
Quote:
create function your_sql_user.NEXTLETTER ( @inputchar char(1) )
returns char(1)
as
BEGIN
declare @asciicode int

-- Gets the ASCII code for the character
set @asciicode = ASCII(@inputchar)

-- According to the ASCII table, these values are not letters. Return 0
IF (@asciicode < 65) or (@asciicode > 90 and @asciicode < 97) or (@asciicode > 122)
return '0'

-- If it's 'Z' set to the value before 'A'
IF (@asciicode = 90)
set @asciicode = 64
-- If it's 'z' set to the value before 'a'
IF (@asciicode = 122)
set @asciicode = 96

-- Increment the ASCII code and convert it back to character
return CHAR(@asciicode + 1)

END


It works on Microsoft SQLServer, but probably the script can be changed for using with other databases, or any programming language
Back to top
View user's profile Send private message MSN Messenger
jefflowrey
PostPosted: Fri Sep 10, 2004 7:13 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

romudd wrote:
This may be done by incrementing the ASCII code for the letter.


ESQL doesn't have an ASCII code function.

The translate function might be useful. This is tested and seems to work...
Code:
translate(inputValue,'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ','bcdefghijklmnopqrstuvwxyzaBCDEFGHIJKLMNOPQRSTUVWXYZA');

_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
Ramphart
PostPosted: Sun Sep 12, 2004 11:25 pm    Post subject: Reply with quote

Disciple

Joined: 21 Jul 2004
Posts: 150
Location: South Africa, JHB

Hi Jeff,

Is the translate function available in WMQI 2.1 CSD 07 on Windows 2000? I can't seem to find any documentation on it.

Regards.
_________________
Applications Architect
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Mon Sep 13, 2004 4:37 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Ramphart wrote:
Is the translate function available in WMQI 2.1 CSD 07 on Windows 2000? I can't seem to find any documentation on it.


No, I don't think so.

I'm fairly sure it's a v5 only function.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
Galichet
PostPosted: Mon Sep 13, 2004 5:05 am    Post subject: Reply with quote

Acolyte

Joined: 26 Jun 2001
Posts: 69
Location: Paris - France

Hi,
You can try the following proposition :

Create a Table like this
---------------------------
CREATE TABLE TABLECONVERT
("TABIN" VARCHAR(255) ,
"TABOUT" VARCHAR(255),
"PAD" CHAR(1) NOT NULL
);

INSERT INTO TABLECONVERT VALUES(
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
'0123456789bcdefghijklmnopqrstuvwxyzaBCDEFGHIJKLMNOPQRSTUVWXYZA',
' ') ;

In a compute node
----------------------
(Assuming that SourceValue contains the field you want to translate)

DECLARE REQ_CONV CHARACTER;
SET REQ_CONV ='select translate(cast(? as varchar(255)), tabout, tabin, pad) as TEMP from TableConvert ';

SET OutputLocalEnvironment.Variables.TargetValue[] = PASSTHRU(REQ_CONV, SourceValue));



I think it should work ... Each character in your SourceValue will be translated according to the table. If a character is not found a space will be used. Beware if you have characters with accents like éèàî ... you have to include them too in the table

I hope this can help you
_________________
Eric Galichet
SMABTP
France
Back to top
View user's profile Send private message Send e-mail
jefflowrey
PostPosted: Mon Sep 13, 2004 5:09 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Or you could use a combination of substring and Position on the formed strings 'abcde..', etc, to avoid using a database table and a fairly expensive passthru.

Something like (when I use the phrase "something like", it means "untested code") - substring('bcdef...' from position(inputvalue in 'abcd...') for 1)
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
Ramphart
PostPosted: Mon Sep 13, 2004 5:43 am    Post subject: Reply with quote

Disciple

Joined: 21 Jul 2004
Posts: 150
Location: South Africa, JHB

Hi Jeff,

Substring and postion is a great idea.

This is what i've done:

/*********************************************************************
** FUNCTION NextChar
**********************************************************************/
CREATE FUNCTION NextChar (value CHAR) RETURNS CHAR
BEGIN
DIM strRange CHAR;
SET strRange = 'ABCDEFGHIJKLMNOPQRSTUVWXYZA';

SET value = UCASE(value);
SET value = SUBSTRING(strRange FROM POSITION(value IN strRange) + 1 FOR 1);
RETURN value;
END;


Thx man
_________________
Applications Architect
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 » How to get next alphabet char ?
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.