-1

I need to replace following characters in two places (nodejs app and SQL Server database). Characters are: - ( , . ) [ ] _

String can be in any language like English, Japanese etc.

Node Js and SQL server both has replace in-built function and I am using that. These inbuild function is not doing the work.

In Node js when I read data from database using package "node-mssql" it is getting converted to question mark and replace is not working.

In SQL Server, the replace function is treating drawing line as dash and replacing it with empty string.

What is the right way to do it in both SQL Server and Node Js.

SQL Server version is 2016

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Anil
  • 1,669
  • 5
  • 19
  • 44
  • Your question is not clear? You want a common replace function in both SQL Server and NodeJS? If you don't want a common method then it needs to be 2 questions. And you need to provide some example data to illustrate what you are trying to accomplish and why its not working. – Dale K Aug 19 '19 at 20:16
  • 1
    You have multiple issues here and it will serve you better to separate them into different questions. First, you have an application problem that allows characters to get into the database that should not be allowed. Next, you need to fix the existing data in your database. Next, you have a problem retrieving strings in your app and not seeing exactly what is in the database once retrieved. Lastly you have an application problem about removing undesirable characters from a string. All of those are part of your issue but you can't address all of them at once. Divide and conquer. – SMor Aug 19 '19 at 20:29

1 Answers1

0

SQL Server 2017+ TRANSLATE:

SELECT TRANSLATE(column, N'-(,.)[]_', N'        ')
FROM tab

For SQL Server you could use REPLACE function.

In SQL Server, the replace function is treating drawing line as dash and replacing it with empty string.

You should mark literals with N (NVARCHAR):

SELECT REPLACE(N'━', N'-', N'');
-- ━

SELECT REPLACE('━', '-', '')
-- ?

db<>fiddle demo

Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275