Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace statment not working

Status
Not open for further replies.

cameron40

Programmer
Sep 21, 2004
4
0
0
GB
What i am trying to do is go through all untype coloum and replace all occurances of 'c' with 'x' can anyone see where my code is wrong because it will not work thanx

replace untype with 'x' where untype = 'c'
 
Replace untype with 'x' for untype = 'c'

boyd.gif

 
Just like craig said, except, you must do "ALL"

Replace untype with 'x' for untype = 'c' && will replace the current record. or the first matching record.

replace ALL untype with 'x' for untype = 'c' will do all of them as you wanted it to be.

Ali Koumaiha
Wireless Toyz
Farmington Hills, Michigan
 
Craig is right. FOR has a scope of ALL. Catches me all the time when I use a SCAN and wonder why nothing after my 1st replace statement seems to get executed.

Brian
 
cameron40

A worthwhile habit to adopt is adding
Code:
[COLOR=blue]IN TABLENAME[/color]
to such statements.

It means you do not have select a specific table before deleting, replacing etc.

You may also run into problems if you don't prefix the field name with the table name should you have any variables with the same name.

So your code might look like
Code:
[COLOR=blue]REPL TABLENAME.untype with 'x' for TABLENAME.untype = 'c' IN TABLENAME[/color]

FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommander[sup]tm[/sup].com
PDFcommander[sup]tm[/sup].co.uk


 
cameron40

Another gotcha is that your REPL statement with the FOR clause will put the table into an EOF() state regardless of where the matching records were found, so, depending on circumstances, you may need to note the original record and return to it after the REPL statement.

FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommander[sup]tm[/sup].com
PDFcommander[sup]tm[/sup].co.uk


 
Good god, i have always used it. lol

thanks for the tip Craig.

learning something new everyday *wink*

Ali Koumaiha
Wireless Toyz
Farmington Hills, Michigan
 
TeknoSDS said:
learning something new everyday *wink*

[smile] same here! I don't necessarily think that including clauses that would otherwise be implicit is a bad thing. In fact as Chris has pointed out it can keep you out of hot water sometimes and lead to more readable code. I almost always include the table name and hardly ever use the abbreviation of commands just for this reason. And, I do happen to use SCAN ALL when I am scanning even though it's not necesssary. So, nothing at all wrong with including the ALL as you've always done, I just didn't want to have the impression left that the ALL was necessary in order to ensure the proper scope.

boyd.gif

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top