Replacing /(forward slash) with a -(dash)

  • I'm trying to replace a forward slash with a dash but I'm not having any luck.  The column I want to do this replace in is a varchar(50). Here is what I'm running that isn't working:

    SELECT     child2, REPLACE(child2, '/', '-') AS Expr1

    FROM         dbo.cs_ArticleCategories

    Can you help me get this to work?

    Thanks!

    James

     

     

  • What is it returning?

  • try substituting char() instead:

    DECLARE @child2 varchar(50)
    SET @child2 = 'that is a strange/name for a column'
    SELECT REPLACE(@child2, '/', '-') AS Expr1
    SELECT REPLACE(@child2, char(47), char(45)) AS Expr2
    







    **ASCII stupid question, get a stupid ANSI !!!**

  • I run this:

    SELECT REPLACE(child2, char(47), char(45)) AS Expr2

    from cs_ArticleCategories

    and this:

    SELECT REPLACE(child2, '/', '-') AS Expr2

    from cs_ArticleCategories

    Then I run this and I get results of child2 values that have a forward slash in them:

    select child2 from cs_ArticleCategories

    where child2 LIKE '%/%'

    Why isn't this working?

    Thanks!

    James

  • post the data from at least one sample string...

    run it for one sample row and as aaron requested...tell us what you get ?!







    **ASCII stupid question, get a stupid ANSI !!!**

  • Also..where are you running this from...?!?!

    Is it possible that you have more than 1 database with the same table name and you're running the code against one but checking the other (I've done that myself sometimes hence the quesition.. )







    **ASCII stupid question, get a stupid ANSI !!!**

  • SELECT REPLACE(child2, char(47), char(45)) AS Expr2

    from cs_ArticleCategories

    where id = 637

    This displayed:

    CSU-DSU

    But when I ran this:

    select child2 from cs_ArticleCategories

    where child2 LIKE '%/%' and id = 637

    It displayed:

    CSU/DSU

    How do I really update this column?

  • Aah.....

    in your "select...replace..." statement, remove the "AS Expr2"!







    **ASCII stupid question, get a stupid ANSI !!!**

  • sorry...my bad...it should be :

    UPDATE cs_ArticleCategories
    SET child2 = REPLACE(child2, char(47), char(45)) 
    WHERE id = 637
    

    sorry..not thinking st. today..







    **ASCII stupid question, get a stupid ANSI !!!**

  • That worked perfectly. Thanks Sushila!

Viewing 10 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply