Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 7 of 7 total
Thread Sql statement to change a character by another in a string
Thu, Aug 26 2010 8:22 AMPermanent Link

Francisco Fernandez

NewTRON Informatica

Avatar

Hello!

I need to change the caracter '¥' with the caracter 'Ñ' in a customer database name.

How can i do?

Thanks
Thu, Aug 26 2010 10:51 AMPermanent Link

Uli Becker

Francisco,

this was my first idea:

SCRIPT
BEGIN
   DECLARE Result CURSOR FOR Stmt;
   DECLARE OldName VARCHAR;
   DECLARE NewName VARCHAR;

   PREPARE Stmt FROM
      'SELECT Name from configuration.databases where name like ''%¥%''';
   OPEN Result;
   FETCH FIRST FROM Result(Name) into OldName;
   WHILE NOT EOF(Result) DO
      SET NewName = Replace('¥' with 'Ñ' in OldName);
      Execute Immediate 'RENAME DATABASE "' + OldName + '" to "' +
NewName + '"';
   FETCH NEXT FROM Result(Name) into OldName;
   END WHILE;
END

Unfortunately there is an error with the composed statement "Rename
database...". It does accept OldName as variable but it doesn't accept
NewName. Tim will tell us, why.

Uli
Thu, Aug 26 2010 10:53 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Francisco


Depending on the version (it came in with 2.03 some build) you have

RENAME TABLE "Contacts" TO "People"

Mix in a little StringReplace when to create the sql and that should do it.

Roy Lambert [Team Elevate]
Fri, Aug 27 2010 3:44 AMPermanent Link

Francisco Fernandez

NewTRON Informatica

Avatar

Roy Lambert wrote:

Francisco


Depending on the version (it came in with 2.03 some build) you have

RENAME TABLE "Contacts" TO "People"

Mix in a little StringReplace when to create the sql and that should do it.

Roy Lambert [Team Elevate]


Roy Lambert wrote:

Francisco


Depending on the version (it came in with 2.03 some build) you have

RENAME TABLE "Contacts" TO "People"

Mix in a little StringReplace when to create the sql and that should do it.

Roy Lambert [Team Elevate]


Hi Roy, I have the 2.03 version, but the sentence don't run. I write this:

UPDATE CODPOS
SET POBLACION = StringReplace(POBLACION, '¥', 'Ñ',[rfReplaceAll])

And this is the error:
ElevateDB Error #700 An error was found in the statement at line 2 and column 51 (Expected expression but instead found [)

If I write this:
UPDATE CODPOS
SET POBLACION = StringReplace(POBLACION, '¥', 'Ñ')

this is the error.

ElevateDB Error #700 An error was found in the statement at line 2 and column 17 (ElevateDB Error #401 The function StringReplace does not exist in the schema Default)


Thanks!
Fri, Aug 27 2010 6:43 AMPermanent Link

Uli Becker

Francisco

> UPDATE CODPOS
> SET POBLACION = StringReplace(POBLACION, '¥', 'Ñ',[rfReplaceAll])

please lookup the right syntax in the manual. It's

REPLACE(<StringExpression> WITH <StringExpression>
        IN <StringExpression>)
REPLACE(<StringExpression>, <StringExpression>,
        <StringExpression>)
<StringExpression> =
Type of:
CHARACTER|CHAR
CHARACTER VARYING|VARCHAR
GUID
CHARACTER LARGE OBJECT|CLOB

So in your case you have to use:

UPDATE CODPOS
SET POBLACION = REPLACE( '¥' WITH 'Ñ' IN POBLACION)

Another thing: you requested a solution for renaming a database, the
above statement just updates a value in a table.

Uli
Sat, Aug 28 2010 8:38 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Uli,

<< Unfortunately there is an error with the composed statement "Rename
database...". It does accept OldName as variable but it doesn't accept
NewName. Tim will tell us, why. >>

I tried the following script here and it worked fine (2.04 syntax for
FETCH):

SCRIPT
BEGIN
  DECLARE Result CURSOR FOR Stmt;
  DECLARE OldName VARCHAR;
  DECLARE NewName VARCHAR;

  PREPARE Stmt FROM
     'SELECT Name from configuration.databases where name like
''%compare%''';
  OPEN Result;
  FETCH FIRST FROM Result('Name') into OldName;
  WHILE NOT EOF(Result) DO
     SET NewName = Replace('compare' with 'Compare' in OldName);
     Execute Immediate 'RENAME DATABASE "' + OldName + '" to "' + NewName +
'"';
  FETCH NEXT FROM Result('Name') into OldName;
  END WHILE;
END

--
Tim Young
Elevate Software
www.elevatesoft.com
Sat, Aug 28 2010 9:11 AMPermanent Link

Uli Becker

Tim,

> I tried the following script here and it worked fine (2.04 syntax for
> FETCH):

You are right: it works fine here as well.

But I swear I wasn't able to execute this script. Anyway...

Regards Uli
Image