Given data in a column which look like this:
00001 00
00026 00
I need to use SQL to remove anything after the space and all leading zeros from the values so that the final output will be:
1
26
How can I best do this?
Btw I’m using DB2
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This was tested on DB2 for Linux/Unix/Windows and z/OS.
You can use the
LOCATE()function in DB2 to find the character position of the first space in a string, and then send that toSUBSTR()as the end location (minus one) to get only the first number of the string. Casting toINTwill get rid of the leading zeros, but if you need it in string form, you canCASTagain toCHAR.