Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 05-10-2012, 08:45 PM
delphimpd delphimpd is offline
Senior Member
 
Join Date: Oct 2006
Posts: 701
Default Replacing Tittle Name Characters Casing

Hi All and thanks for the Help.

I have about 300 records which contains the following characters "OFC." in my Table Name, Name Tittle field

Example OFC.Mark Smith, is a faulty Tittle that needs to be change from OFC. Mark Smith to Ofc. Mark Smith

Now, I need to run a process to all these names, and Change from the Current "OFC" to "Ofc" So this is what I do, and what I need the help on. All I need to Change are the 3 characters only, the Period is not a problem.

Code:
qryNames.First;

While Not qryNames.Eof do
 begin
    //Here I need to identify if the Name is Correct (Like Ofc. Brandon Woop)
    //So , if it is Correct 
      qryNames.Next; //Move on to the Next name until the faulty that needs to be corrected is found

    //So, if the Name Contains the Characters "OFC" like OFC. Mark Smith then


  qryNames.Edit;
   //Here the Name gets edited with the right Characteres "Ofc"
   qryName.Post;
   qryNames.Next;
 end;


I Hope that you could help me out with this.

Thanks
Reply With Quote
  #2  
Old 05-10-2012, 10:22 PM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,055
Default

This could be done easily by SQL. Look for Upper case and some other functions in the DB engine that you are using. If you need more help tell me the DB engine name and some other info about the fields and I will try to build the SQL clause for you.
__________________
Regards,
Abdulaziz Jasser

Last edited by Jasser; 05-12-2012 at 09:54 AM.
Reply With Quote
  #3  
Old 05-10-2012, 10:57 PM
delphimpd delphimpd is offline
Senior Member
 
Join Date: Oct 2006
Posts: 701
Default

Hi Jasser,

Long while we dont chat.

Thanks for the Help

The DB is MS SQL and the field is a varchar(50)

Thanks

Regards,
Reply With Quote
  #4  
Old 05-11-2012, 03:26 AM
GeoWink GeoWink is offline
Senior Member
 
Join Date: Jan 2001
Posts: 879
Default

What about going through each record, look for OFC and change it to Ofc. That's just a Find and replace. Isn't that what you need?

George
Reply With Quote
  #5  
Old 05-12-2012, 07:57 AM
delphimpd delphimpd is offline
Senior Member
 
Join Date: Oct 2006
Posts: 701
Default

Hi GeoWink.

Thanks for the Help and reference .

You are correct, and that hinted me out to look for this

http://www.delphibasics.co.uk/RTL.as...dCode1=Yes#Ex1

However, I also would like to see Jasser's SQL Update commands.

Your suggestion and Jasser could greatly help others as well.

Thanks
Reply With Quote
  #6  
Old 05-12-2012, 09:50 AM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,055
Default

It should be something like:


Code:
UPDATE TABLE1 SET NameTitle = "Ofc" + MID(NameTitle,4,47) 
WHERE MID(NameTitle,1,3) = "OFC"
__________________
Regards,
Abdulaziz Jasser
Reply With Quote
  #7  
Old 05-14-2012, 03:17 AM
delphimpd delphimpd is offline
Senior Member
 
Join Date: Oct 2006
Posts: 701
Default

Hi Jasser and Thanks for the help

Your help actually returned an error, however, it guided me to this Page

http://www.sqlteam.com/article/using...date-statement

There I used this method

This will go to all the records in my Name Table find the string "OFC" and replacing it with "Ofc" Leaving the Name Intact.

Code:
Update dbo.Names
Set    Full_Name = replace(Full_Name, 'OFC', 'Ofc');
Once again thank you both of you guys for helping me out.

Regards
Reply With Quote
  #8  
Old 05-15-2012, 07:05 PM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,055
Default

It is good that you solved it. However, those SQL clauses are different from one engine to another and since I did not have MS SQL I gave you an example of an SQL clause that would work on MS Access assuming that it will work on MS SQL (both are from MS $). In the DB engine that I'm using it does support "Replace" function but in a little different syntax.

Code:
UPDATE Names
SET Full_Name = REPLACE( 'OFC' WITH 'Ofc' IN Full_Name);
Therefore, it is very hard to tell the right answer when it is about engine specific SQL clauses.
__________________
Regards,
Abdulaziz Jasser
Reply With Quote
  #9  
Old 05-22-2012, 06:45 PM
delphimpd delphimpd is offline
Senior Member
 
Join Date: Oct 2006
Posts: 701
Default

Jasser
Thanks for the help anyways. So now anyone from access and ms sql dabase will benefit.

Regards.
Reply With Quote
  #10  
Old 05-18-2015, 07:44 PM
GeoWink GeoWink is offline
Senior Member
 
Join Date: Jan 2001
Posts: 879
Default

I did this using Delphi 2009 and it works just fine. I get single quotes.

George
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 09:12 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2017, vBulletin Solutions, Inc.