Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Update syntax with Replace and Cast
Message
 
 
À
06/04/2015 15:20:20
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2012
Application:
Web
Divers
Thread ID:
01617831
Message ID:
01617833
Vues:
39
>I have an update command like this:
>
>
>UPDATE EmailTemplate SET Subject_E=CAST(REPLACE(CAST(UPPER(Subject_E) AS NVarchar(MAX)),'[OldMemberTableName]','[Member]') AS NText)
>
>
>This works but it is case sensitive.
>
>If "OldMemberTableName" is like "OLDMEMBERTABLENAME", it will not be replaced.
>
>I tried inserting UPPER( syntax in there but it never replaces it properly.
>
>How can I make such command case insensitive?

Why do you need to cast to nvarchar(max) and not varchar(max)? Are you using unicode? Also, why do you need to cast back to ntext? I don't think you need to cast back and it should work fine.

BTW, this works fine for me (e.g. both strings are replaced):
drop table #test
go
create table #test(Subject_E nvarchar(max))

insert into #test (Subject_E) values ('Testing [OldMemberTableName]'), ('Testing [OLDMEMBERTABLENAME]')

UPDATE #test SET Subject_E=replace(Subject_E ,'[OldMemberTableName]','[Member]')
select * from #test
What is the database collation and table column collation?
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform