Archives of the TeradataForum
Message Posted: Sun, 16 May 2004 @ 20:24:56 GMT
It looks like you want the results of the CHAR2HEXINT function cast as a smallint, eg.
SELECT CAST( CHAR2HEXINT( SUBSTR( MSG_DATA, 45, 1 ) ) AS SMALLINT )
Of course, you can't do this directly since the CHAR2HEXINT function returns strings like '7E', for example, when the source data = '~'.
You can take the result of the CHAR2HEXINT function and use it in the following expression to compute the number you want:
SELECT POSITION ( SUBSTR( CHAR2HEXINT( SUBSTR( MSG_DATA, 45, 1 ) ), 1, 1 ) IN '123456789ABCDEF0' ) MOD 16 * 16 + POSITION ( SUBSTR( CHAR2HEXINT( SUBSTR( MSG_DATA, 45, 1 ) ), 2, 1 ) IN '123456789ABCDEF0' ) MOD 16
In the case of the source data = '~', CHAR2HEXINT will return the string '7E'. The expression above substrings the first character, '7', finds this characer at position 7 in the position function, and multiplies 7 by 16 to get 112. Then you substring the second character, 'E', find it at position 14, and add 14 to 112 to get the final answer = 126.
|Copyright 2016 - All Rights Reserved|
|Last Modified: 27 Dec 2016|