Solved

Remove the last zero character form a string

Posted on 2009-04-09
12
368 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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
 

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

810 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