473,836 Members | 1,333 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

2 New Member

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
  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 ".


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 12598
127 Recognized Expert New Member
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(stri ng and integer).

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

-- Sanjay
Mar 21 '08 #2
2 New Member
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 :-

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
297 Recognized Expert Contributor

try a

Expand|Select|Wrap|Line Numbers
  2. THEN
  3.   insert your cast statement
  4. ELSE
  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?


Mar 22 '08 #4

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

Similar topics

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 * is 4 bytes, should the following yield 4, 5, of something else? (And, if something else, what determines the result?) char x = "abcd"; printf( "%d\n", sizeof( x ) ); -Don
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 at the end and how can I do this? I tried pos='\0' after my last memcpy and that doesn't work either. ============================================================= void ERR(char * err_msg){
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 DBT_DEVICEARRIVAL or DBT_DEVICEREMOVECOMPLETE. I want to identify the device that has arrived or been removed by examining the dbcc_name member of the DEV_BROADCAST_DEVICEINTERFACE structure.
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 zero-length string (always returns a zero-length string when used in a query expression)" **** How many records are there in FirstTable in which Product Is Null. SELECT COUNT(*) AS CountofNullProdcut
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 has prepared for those who love him" 1 Cor 2:9
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 00000000000000001111111111111111 11111111111111111111111111111111 00000000000000000000000000000000 11111111111111110000000000000000
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 set of examples, after decoding the HTML FORM contents, merely verifies the text within a field to make sure it is a valid representation of an integer, without any junk thrown in, i.e. it must satisfy the regular expression: ^ *?+ *$ If the...
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 (Java). It stores character strings, and resizes itself to accommodate new strings when needed. Interface: ----------
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. This is what I have so far: #include <stdio.h> #include <stdlib.h> #include <string.h>
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.