Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2006
    Posts
    1

    Unanswered: How do I replace a substring within string??

    I'm using the following code to replace a substring within a string:

    UPDATE SchedUNIXJob
    SET JobFailInstrTxt = STUFF(JobFailInstrTxt, CHARINDEX('next morning', JobFailInstrTxt), 12, 'IMMEDIATELY')
    FROM SchedUNIXJob S, ApplicationCdeVal A
    WHERE CHARINDEX('next morning', JobFailInstrTxt) != 0
    AND A.ApplicationTxt = "ebisrpt"
    AND S.ApplicationCde = A.ApplicationCde



    But, I'm getting the following error:
    07:07:02.514 DBMS TDS_SY24 -- Error: Number (11021) Severity (16) State (2) Server (TDS_SY24) Function CHARINDEX invoked with wrong number or type of argument(s).

    thanks

  2. #2
    Join Date
    Jan 2003
    Location
    Geneva, Switzerland
    Posts
    353
    If you are using ASE 12.5 or later, consider using str_replace() instead...

    Michael

  3. #3
    Join Date
    Nov 2006
    Posts
    13
    try thisone.

    declare @a varchar(12),@b varchar(12)
    select @a='come next morning'
    select @b='immediately'

    select stuff(@a,charindex("next",@a),12,,@b).

    It will give you the expected result.

    --Asit

  4. #4
    Join Date
    Jul 2006
    Posts
    115
    OR:

    declare @a varchar(255),@b varchar(255),@c varchar(255)
    select @a='come next morning'
    select @b='immediately'
    select @c='next'

    select stuff(@a,charindex(@c,@a),datalength(@c),@b)

    Result: come immediately morning

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •