473,738 Members | 11,192 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
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 12593
sakumar9
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 !

Regards
-- Sanjay
Mar 21 '08 #2
amija0311
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 :-
--------------
CAST(LTRIM(RTRI M(TRANSLATE('1A ', ' ', 'ABCDEFGHIJKLMN OPQRSTUVWXYZ')) ) 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 Recognized Expert Contributor
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
17458
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
11
1825
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){
5
7734
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.
10
4588
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
33
3672
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
7
19224
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
232
13308
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...
3
5091
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: ----------
14
13521
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>
0
8969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9476
Oralloy
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...
0
9335
jinu1996
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...
0
9208
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8210
agi2029
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...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3279
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
2
2745
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
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.