Use a Like in a Replace Cast sentence?

  • Hi, i would appreciate suggest the SQL sentence, thanks

    CREATE TABLE [dbo].[instructions](

    [site_no] [int] NOT NULL,

    [instructions] [text] NULL

    )

    Select top 3 * from instructions

    Output

    Site_no Instructions

    20 Request PIN#510 then proceed

    21 Request PIN#987 if wrong request name

    22 Request PIN#688 allowed to use only numbers

    All text instructions start with “Request PIN#XXX” also after that the text are different for every site_no

    I need insert in all site_no rows and after the “Request PIN#XXX” the text “and codeword” keeping the current rest of text

    How can I set e REPLACE CAST sentence using something LIKE PIN%%%%

    To get these type of results

    site_no instructions

    ----------- ----------------------------------------------------

    20 Request PIN#510 and codeword then proceed

    21 Request PIN#987 and codeword if wrong request name

    22 Request PIN#688 and codeword allowed to use only numbers

    Can you please suggest the right update SQL sentence? Beforehand thank you

  • Take a look at the STUFF function.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Additional to that, you should really change your text columns into varchar(max) or even a normal varchar. The text datatype has been deprecated and will be removed in a future version. Additional to that, it's really a PITA to work with that datatype.

    Other than that, the STUFF() function and probably CHARINDEX() will do the trick. 😉

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Thanks Koen

  • Gracias Luis

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

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