473,322 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How to translate string with data have integer + character and null data

Hi,

I am new using DB2 9.1 database by windows base.
I want to query the data that contain string then translate the string into integer using DB2.
The problems is If the data is null, i got the problem to translate.
How to translate string also allow null data to integer. If null data it will read as space.

My Data :-

Expand|Select|Wrap|Line Numbers
  1. GEOSEG_ID     SEQNO      
  2. ----------  ---------
  3. 329802           2
  4. 329803           3A
  5. 329805           1A
  6. 329806          10
  7. 329808          11A
  8. 329810           9
  9. 329811           4
  10. 329812           6
  11. 329813           5
  12. 329814           7
  13. 329815           8A
  14. 329843          13A
  15. 329844          20
  16. 329845          21
  17. 329846          19
  18. 329848          14
  19. 329849          16
  20. 329850          15
  21. 329851          22
  22. 329852          18
  23. 329854          24
  24. 329855          23
  25. 329868         NULL
  26. 329869        NULL
  27. 329870         NULL
  28. 329871         NULL
  29. 329872         NULL
  30. 329873         NULL
This is My Query :-
-----------------
Expand|Select|Wrap|Line Numbers
  1. Select geoseg.geoseg_id,CAST(LTRIM(RTRIM(TRANSLATE(Elot_detail1.sequence, ' ', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'))) AS INTEGER) AS seqNo
  2. FROM  GEOSEG,ELOT_DETAIL1 
  3. WHERE    ELOT_DETAIL1.GEOSEG_ID  = GEOSEG.GEOSEG_ID
  4. ELOT_DETAIL1.POSTCODE  = '41200'
  5. AND    ELOT_DETAIL1.BIT  = '41'  
  6. GROUP BY  GEOSEG.GEOSEG_ID,Elot_detail1.sequence  
Sql error will appear like this :-
---------------------------------

SQL0420N Invalid character found in a character string argument of the
function "INTEGER". SQLSTATE=22018

SQL0420N Invalid character found in a character string argument of the function "INTEGER ".

Explanation:

The function "<function-name>" has a character string argument
that contains a character that is not valid in a numeric SQL
constant. The function may have been called as a result of using
the CAST specification with "<function-name>" as the target data
type. The function or data type used in the SQL statement may be
a synonym for "<function-name>".

If a decimal character is specified in the DECIMAL function then
that is the character that must be used in place of the default
decimal character.

User Response:

Ensure that the character strings that are being converted to
numeric types contain only characters that are valid in numeric
SQL constants, using the decimal character, if specified.

sqlcode : -420

sqlstate : 22018
Mar 21 '08 #1
3 12474
sakumar9
127 Expert 100+
I am not able to understand why do you want this conversion from string to integer?

You cannot cast any string into integer......... they are not compatible....... i mean it doesn't makes any sense to me atleast.......

By the way, the error which you are getting is because of CAST function that you are using. CAST is trying to convert a string into an INTEGER which is not compatible(string and integer).

If you can explain what you really want to achieve, that would be great !

Regards
-- Sanjay
Mar 21 '08 #2
Sorry because not explain well.

Actually i want to translate the sequence it will change string that have character to space "".

Like 1A it will read 1 and space.

example :-
--------------
CAST(LTRIM(RTRIM(TRANSLATE('1A', ' ', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'))) AS INTEGER)

This query will done perfectly.

But if the data NULL, it will got error. How to make this query also can read NULL data and change it to space.
Mar 21 '08 #3
docdiesel
297 Expert 100+
Hi,

try a

Expand|Select|Wrap|Line Numbers
  1. CASE WHEN NOT (SEQNO IS NULL)
  2. THEN
  3.   insert your cast statement
  4. ELSE
  5.  
  6. END;
Or maybe you'd like to leave it NULL instead of turning it to zero (0) in the ELSE part. Does this work for you?

Regards,

Bernd
Mar 22 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: Don Starr | last post by:
When applied to a string literal, is the sizeof operator supposed to return the size of the string (including nul), or the size of a pointer? For example, assuming a char is 1 byte and a char *...
11
by: jt | last post by:
Here is my code below, it doesn't printf. But I step it thru using the for statement and use putchar to the display, its there... How can I get it to use printf? If the problem is needing a null...
5
by: jan axelson | last post by:
My application is using RegisterDeviceNotification() to detect attachment and removal of a USB HID-class device. The form is receiving WM_DEVICECHANGE messages with wParam set to...
10
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaac11/html/acfctNZ_HV05186465.asp "If the value of the variant argument is Null, the Nz function returns the number zero or a...
33
by: Jordan Tiona | last post by:
How can I make one of these? I'm trying to get my program to store a string into a variable, but it only stores one line. -- "No eye has seen, no ear has heard, no mind can conceive what God...
7
by: elliotng.ee | last post by:
I have a text file that contains a header 32-bit binary. For example, the text file could be: %%This is the input text %%test.txt Date: Tue Dec 26 14:03:35 2006...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
3
by: jacob navia | last post by:
Abstract: Continuing the discussion about abstract data types, in this discussion group, a string collection data type is presented, patterned after the collection in C# and similar languages...
14
by: rtillmore | last post by:
Hello, I did a quick google search and nothing that was returned is quite what I am looking for. I have a 200 character hexadecimal string that I need to convert into a 100 character string. ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.