[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Remove the last zero character form a string

Posted on 2009-04-09
12
Medium Priority
?
381 Views
Last Modified: 2012-05-06
Hi;
I have a string field full of data like this" 18 10 6 4 1 0"
I mean that is the last character always space then zero "0"
I need function  to remove this zero  at all
please
0
Comment
Question by:Mohammad Alsolaiman
  • 6
  • 5
12 Comments
 
LVL 5

Assisted Solution

by:brandonvmoore
brandonvmoore earned 200 total points
ID: 24113557
Use the Left() and Len() functions:

select left(fieldname, len(fieldname) - 1)
or
select left(fieldname, len(fieldname) - 2)

Use "-1" if you want to leave the space on the end or "-2" if you want to get rid of the space and the 0.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24113567
what if you had something ending with 10, is that a possibility?
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24113573
if always space then 0 then brandon's post will work for you. If not always space and 0 then try this

if last two chars is space and 0 then strip it off else leave as as

mystrippedfield: iif(right$(myfield,2) = " 0",left$(myfield,len(myfield)-2),myfield)

this can be put in your sql

0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 65

Expert Comment

by:rockiroads
ID: 24113575
is this stripping just for display purposes or do you want to update the data? what Ive posted is for select. If you want to update the data, it is like this

update mytable
set myfield = left$(myfield,len(myfield)-2)
where len(nz(myfield,""))>1 and right$(myfield,2) = " 0"

Need to actually take into account any fields that are null or have 1 char in them so added len(nz(myfield,""))>1
same would be needed in the select as well I guess


0
 

Author Comment

by:Mohammad Alsolaiman
ID: 24113600
no i want some thing fore fields i declare, but not in sql statement
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 1800 total points
ID: 24113609
sorry? fields you declare. Do you want vba

dim mynewstring as string

mynewstring = iif(right$(myfield,2) = " 0",left$(myfield,len(myfield)-2),myfield)

Otherwise Im not sure what you mean
0
 

Author Comment

by:Mohammad Alsolaiman
ID: 24113636
yes u r wright,
but there some thing else
i think the zero is in the first character,  and not as i mention before .
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24113658
so it is zero and space
or space and zero

if zero and space

if len(myoldstring)>1 and left$(myoldstring,2) = "0 " then
    mynewstring = myoldstring
else
    mynewstring = myoldstring
end if

to replace myoldstring only

if len(myoldstring)>1 and left$(myoldstring,2) = "0 " then
    myoldstring = mid$(myoldstring,3)
end if


to replace space and zero, change "0 " to " 0"
0
 

Author Closing Comment

by:Mohammad Alsolaiman
ID: 31568826
wonderful
0
 

Author Comment

by:Mohammad Alsolaiman
ID: 24113667
thanks a lot rocki
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24113694
No probs
in case you got null strings, just add the check for the length
0
 

Author Comment

by:Mohammad Alsolaiman
ID: 24114277
clear
thanks again
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question