Solved

Remove the last zero character form a string

Posted on 2009-04-09
12
366 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 50 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
 
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 450 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now