Removing the JUNK Characters

  • Dear All,

    I want to remove the JUNK characters from Remarks column.

    Say for example,

    Create table Emp

    (

    Eno int,

    Salary money,

    Remarks

    )

    Insert into Emp

    Select 1,5000,'Bon#us&@amount'

    union all

    select 2,8000,'Previous,..,month^&^salary'

    Union all

    select 3,10000,',Leave,.Travel allowance'

    Select * from Emp

    Output

    ...........................

    Eno Salary Remarks

    ............................

    1 5000 Bon#us&@amount

    2 8000 Previous,..,month^&^salary

    3 10000 ,Leave,.Travel allowance

    i want to remove the JUNK characters like #&@,.^.

    Expected Output :

    ...........................

    Eno Salary Remarks

    ............................

    1 5000 Bonus amount

    2 8000 Previousmonth salary

    3 10000 LeaveTravel allowance

    Thanks in advance.

    karthik

  • On http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=67997 there is a function that removes these characters.

    Regards,

    Andras


    Andras Belokosztolszki, MCPD, PhD
    GoldenGate Software

  • But Andras i dont want to use any functions. Because i dont have the permission to create functions.

    karthik

  • karthikeyan (4/21/2008)


    But Andras i dont want to use any functions. Because i dont have the permission to create functions.

    That makes it more tricky 🙂 Before trying to find a T-SQL solution in this case, what are you doing with the returned data? Are you processing it in an application? It is much more easier to clean your data on the client (where you can use regular expressions, etc).

    Regards,

    Andras


    Andras Belokosztolszki, MCPD, PhD
    GoldenGate Software

  • karthikeyan (4/21/2008)


    But Andras i dont want to use any functions. Because i dont have the permission to create functions.

    Yes. Tricky. Maybe you can do something along these lines...?

    select 'start' --needed to set @@rowcount > 0

    while @@rowcount > 0

    update Emp set Remarks = stuff(Remarks, patindex('%[^a-zA-Z ]%', Remarks), 1, '')

    from Emp where Remarks like '%[^a-zA-Z ]%'

    Ryan Randall

    Solutions are easy. Understanding the problem, now, that's the hard part.

Viewing 5 posts - 1 through 5 (of 5 total)

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