Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default SQL Replace

    I've looked at BOL and through dejanews for a solution (similar post from
    Lamine Darbouche on 30th July in this group) but cannot find a solution.
    I am trying to replace text within a field using the SP below.

    Alter Procedure cc_globalBodyReplace
    (
    @toReplace varchar(255),
    @replaceWith varchar(255),
    @result integer OUTPUT
    )
    AS
    SET nocount on
    BEGIN
    -- Replace body
    UPDATE PAGE_ATTRIBUTE
    SET BODY = replace(BODY,@toReplace,@replaceWith)
    WHERE BODY like '%'+@toReplace+'%'
    END
    --Return success/fail depending on sql feedback
    IF @@Error = 0
    select @result = 1
    ELSE
    select @result = 0

    I am getting the following error when trying to save it:
    'Argument data type text is invalid for argument 1 of replace function'
    From BOL is suggests all arguments are strings but I've seen mention of it
    being possible to use a column as the first argument.
    I'm using SQL2K SP3a and Visual Studio 6.0 (SP5) as the editor.
    The [BODY] column type is text.

    TIA

    chopper


    Chopper Guest

  2. Similar Questions and Discussions

    1. Replace XML
      I want to replace two parameters on the same replace, the idea it's print in a textArea a XML file from a webService, went i get the XML, but this...
    2. help with the replace(pattern, replace)
      hii i hope you can help me, i want to replace two parameters on the same replace, the idea it's print in a textArea a XML file from a webService,...
    3. Replace into..??
      Hallo Group, is there an equivelant/replacement of the MySQL Command "Replace Into" for Access/MS SQLServer? "Replace Into" does either...
    4. Search and replace (super global replace)
      I am using the 30 day trail of acrobate professional....before I buy it I have a few questions.... 1) is there a "search and replace" function...
    5. Replace in ASP/VBS/SQL
      I need to replace all occurancies of "is" in "This is a test (is), is, penis." with "<a href=is.htm>is</a>". The thing is, if I use a simple...
  3. #2

    Default Re: SQL Replace

    The error is just what it says it is. You need to change the type from text
    to varchar. If that's not possible, then you can't use the replace function
    in your SP.

    Bob Lehmann

    "Chopper" <chopper@despammed.com> wrote in message
    news:3f9e86bd$0$252$cc9e4d1f@news.dial.pipex.com.. .
    > I've looked at BOL and through dejanews for a solution (similar post from
    > Lamine Darbouche on 30th July in this group) but cannot find a solution.
    > I am trying to replace text within a field using the SP below.
    >
    > Alter Procedure cc_globalBodyReplace
    > (
    > @toReplace varchar(255),
    > @replaceWith varchar(255),
    > @result integer OUTPUT
    > )
    > AS
    > SET nocount on
    > BEGIN
    > -- Replace body
    > UPDATE PAGE_ATTRIBUTE
    > SET BODY = replace(BODY,@toReplace,@replaceWith)
    > WHERE BODY like '%'+@toReplace+'%'
    > END
    > --Return success/fail depending on sql feedback
    > IF @@Error = 0
    > select @result = 1
    > ELSE
    > select @result = 0
    >
    > I am getting the following error when trying to save it:
    > 'Argument data type text is invalid for argument 1 of replace function'
    > From BOL is suggests all arguments are strings but I've seen mention of it
    > being possible to use a column as the first argument.
    > I'm using SQL2K SP3a and Visual Studio 6.0 (SP5) as the editor.
    > The [BODY] column type is text.
    >
    > TIA
    >
    > chopper
    >
    >

    Bob Lehmann Guest

  4. #3

    Default Re: SQL Replace

    REPLACE is not a valid method for TEXT/NTEXT datatypes. See
    [url]http://www.aspfaq.com/2445[/url]





    "Chopper" <chopper@despammed.com> wrote in message
    news:3f9e86bd$0$252$cc9e4d1f@news.dial.pipex.com.. .
    > I've looked at BOL and through dejanews for a solution (similar post from
    > Lamine Darbouche on 30th July in this group) but cannot find a solution.
    > I am trying to replace text within a field using the SP below.
    >
    > Alter Procedure cc_globalBodyReplace
    > (
    > @toReplace varchar(255),
    > @replaceWith varchar(255),
    > @result integer OUTPUT
    > )
    > AS
    > SET nocount on
    > BEGIN
    > -- Replace body
    > UPDATE PAGE_ATTRIBUTE
    > SET BODY = replace(BODY,@toReplace,@replaceWith)
    > WHERE BODY like '%'+@toReplace+'%'
    > END
    > --Return success/fail depending on sql feedback
    > IF @@Error = 0
    > select @result = 1
    > ELSE
    > select @result = 0
    >
    > I am getting the following error when trying to save it:
    > 'Argument data type text is invalid for argument 1 of replace function'
    > From BOL is suggests all arguments are strings but I've seen mention of it
    > being possible to use a column as the first argument.
    > I'm using SQL2K SP3a and Visual Studio 6.0 (SP5) as the editor.
    > The [BODY] column type is text.
    >
    > TIA
    >
    > chopper
    >
    >

    Aaron Bertrand - MVP Guest

  5. #4

    Default Re: SQL Replace

    It's with hesitation I top post but here goes...
    Many thanks all.
    Will let you know how I get on.

    chopper

    "Aaron Bertrand - MVP" <aaron@TRASHaspfaq.com> wrote in message
    news:%23VcjJEXnDHA.2432@TK2MSFTNGP10.phx.gbl...
    > REPLACE is not a valid method for TEXT/NTEXT datatypes. See
    > [url]http://www.aspfaq.com/2445[/url]
    >
    >
    >
    >
    >
    > "Chopper" <chopper@despammed.com> wrote in message
    > news:3f9e86bd$0$252$cc9e4d1f@news.dial.pipex.com.. .
    > > I've looked at BOL and through dejanews for a solution (similar post
    from
    > > Lamine Darbouche on 30th July in this group) but cannot find a solution.
    > > I am trying to replace text within a field using the SP below.
    > >
    > > Alter Procedure cc_globalBodyReplace
    > > (
    > > @toReplace varchar(255),
    > > @replaceWith varchar(255),
    > > @result integer OUTPUT
    > > )
    > > AS
    > > SET nocount on
    > > BEGIN
    > > -- Replace body
    > > UPDATE PAGE_ATTRIBUTE
    > > SET BODY = replace(BODY,@toReplace,@replaceWith)
    > > WHERE BODY like '%'+@toReplace+'%'
    > > END
    > > --Return success/fail depending on sql feedback
    > > IF @@Error = 0
    > > select @result = 1
    > > ELSE
    > > select @result = 0
    > >
    > > I am getting the following error when trying to save it:
    > > 'Argument data type text is invalid for argument 1 of replace function'
    > > From BOL is suggests all arguments are strings but I've seen mention of
    it
    > > being possible to use a column as the first argument.
    > > I'm using SQL2K SP3a and Visual Studio 6.0 (SP5) as the editor.
    > > The [BODY] column type is text.
    > >
    > > TIA
    > >
    > > chopper
    > >
    > >
    >
    >

    Chopper Guest

  6. #5

    Default Re: SQL Replace

    Worked a treat!
    Thanks again.

    chopper

    "Chopper" <chopper@despammed.com> wrote in message
    news:3f9ead55$0$248$cc9e4d1f@news.dial.pipex.com.. .
    > It's with hesitation I top post but here goes...
    > Many thanks all.
    > Will let you know how I get on.
    >
    > chopper
    >
    > "Aaron Bertrand - MVP" <aaron@TRASHaspfaq.com> wrote in message
    > news:%23VcjJEXnDHA.2432@TK2MSFTNGP10.phx.gbl...
    > > REPLACE is not a valid method for TEXT/NTEXT datatypes. See
    > > [url]http://www.aspfaq.com/2445[/url]
    > >
    > >
    > >
    > >
    > >
    > > "Chopper" <chopper@despammed.com> wrote in message
    > > news:3f9e86bd$0$252$cc9e4d1f@news.dial.pipex.com.. .
    > > > I've looked at BOL and through dejanews for a solution (similar post
    > from
    > > > Lamine Darbouche on 30th July in this group) but cannot find a
    solution.
    > > > I am trying to replace text within a field using the SP below.
    > > >
    > > > Alter Procedure cc_globalBodyReplace
    > > > (
    > > > @toReplace varchar(255),
    > > > @replaceWith varchar(255),
    > > > @result integer OUTPUT
    > > > )
    > > > AS
    > > > SET nocount on
    > > > BEGIN
    > > > -- Replace body
    > > > UPDATE PAGE_ATTRIBUTE
    > > > SET BODY = replace(BODY,@toReplace,@replaceWith)
    > > > WHERE BODY like '%'+@toReplace+'%'
    > > > END
    > > > --Return success/fail depending on sql feedback
    > > > IF @@Error = 0
    > > > select @result = 1
    > > > ELSE
    > > > select @result = 0
    > > >
    > > > I am getting the following error when trying to save it:
    > > > 'Argument data type text is invalid for argument 1 of replace
    function'
    > > > From BOL is suggests all arguments are strings but I've seen mention
    of
    > it
    > > > being possible to use a column as the first argument.
    > > > I'm using SQL2K SP3a and Visual Studio 6.0 (SP5) as the editor.
    > > > The [BODY] column type is text.
    > > >
    > > > TIA
    > > >
    > > > chopper
    > > >
    > > >
    > >
    > >
    >
    >

    Chopper Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139