DECLARE @SearchStr varchar( 30 ) , @SearchBin varbinary( 30 )
SELECT @SearchStr = 'AdministraciÓón' ,
@SearchBin = CONVERT( varbinary( 30 ) , @SearchStr )
PRINT 'Original String : ' + @SearchStr
/*
Original String : AdministraciÓón
*/
SE @SearchStr = STUFF( @SearchBin ,
CHARINDEX( CONVERT( binary(1) , 'Ó' ) , @SearchBin ) ,
1 , CONVERT( binary(1) , 'O') )
PRINT 'After Replace #1: ' + @SearchStr
/*
After Replace #1: AdministraciOn
*/
SELECT @SearchBin = CONVERT( varbinary( 30 ) , @SearchStr )
SELECT @SearchStr = STUFF( @SearchBin ,
CHARINDEX( CONVERT( binary(1) , 'ó' ) , @SearchBin ) ,
1 , CONVERT( binary(1) , 'o') )
PINT 'After Replace #2: ' + @SearchStr
/*
After Replace #2: AdministraciOon
*/
-- Mimic behavior of REPLACE using a LOOP
DECLARE @SearchStr varchar( 30 ) , @SearchBin varbinary( 30 ) ,
@CharBin binary( 1 )
SELECT @SearchStr = 'AdministraciÓón de Operación'
SELECT @SearchBin = CONVERT( varbinary( 30 ) , @SearchStr )
SELECT @CharBin = CONVERT( binary(1) , 'Ó' )
WHILE CHARINDEX( @CharBin , @SearchBin ) > 0
SELECT @SearchBin = CONVERT( varbinary( 30 ) ,
STUFF( @SearchBin ,
CHARINDEX( @CharBin , @SearchBin ) ,
1 , CONVERT( binary(1) , 'O') ) )
SELECT @CharBin = CONVERT( binary(1) , 'ó' )
WHILE CHARINDEX( @CharBin , @SearchBin ) > 0
SELEC @SearchBin = CONVERT( varbinary( 30 ) ,
STUFF( @SearchBin ,
CHARINDEX( @CharBin , @SearchBin ) ,
1 , CONVERT( binary(1) , 'o') ) )
SELECT @SearchStr = CONVERT( varchar( 30 ) , @SearchBin )
PRINT @SearchStr
This page was last updated on May 01, 2006 04:28 PM.