dasdsadasdsad asdasdas
dasdsadasdsad asdasdas

Reputation: 123

how to convert any char to - in sql server?

i have one column in sql table like this

    codel
-------------
124/500/319/1
500/2698794/3
130.500.2804508.1
800/283478/2
155-305-340007-1
130.500.2686821.1

how i can convert this code to

     codel
-------------
124-500-319-1
500-2698794-3
130-500-2804508-1
800-283478-2
155-305-340007-1
130-500-2686821-1

thank you for read my qustion

Upvotes: 0

Views: 88

Answers (3)

PSK
PSK

Reputation: 17943

In SQL Server 2017, you can also do it using TRANSLATE like following.

SELECT TRANSLATE(codel,'/.','--') AS Codel FROM YOUR_TABLE

Upvotes: 4

Zaynul Abadin Tuhin
Zaynul Abadin Tuhin

Reputation: 31993

try like below by using replace

   SELECT REPLACE(codel, '/', '-'); 
    go
  SELECT REPLACE(codel, '.', '-'); 

Upvotes: 0

Fahmi
Fahmi

Reputation: 37473

Try below - using replace() function

select replace(replace(codel,'/','-'),'.','-') from tablename

Upvotes: 2

Related Questions