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

  1. #1

    Default Replace into..??

    Hallo Group,

    is there an equivelant/replacement of the MySQL Command "Replace Into" for
    Access/MS SQLServer?

    "Replace Into" does either inserting or updating of data, depending on
    whether the record exists or not. And I would love to avoid 2 differnet
    functions for this.

    regards,
    Michael Posthoff



    Michael Posthoff 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. 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...
    4. 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....
    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: Replace into..??

    Michael Posthoff wrote:
    > Hallo Group,
    >
    > is there an equivelant/replacement of the MySQL Command "Replace
    > Into" for Access/MS SQLServer?
    >
    > "Replace Into" does either inserting or updating of data, depending on
    > whether the record exists or not. And I would love to avoid 2
    > differnet functions for this.
    No, you have to do a two-stage process: run an update query to update
    records that meet the requirements. If no records meet the requirements,
    insert the new records.

    Bob Barrows

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.


    Bob Barrows [MVP] Guest

  4. #3

    Default Re: Replace into..??

    That is on the WishList for SQL Server (most people coin it as an "upsert").
    However, it is not implemented in current versions of SQL Server, and is
    unlikely to make the next version, either.

    The usual workaround is a single stored procedure (you don't use a function
    to insert/update!) that takes the input parameters, then has logic like
    this:

    IF EXISTS (SELECT 1 FROM tbl WHERE [primary key] = @param2)
    UPDATE tbl SET whatever = @param1 WHERE [primary key] = @param2
    ELSE

    INSERT tbl(whatever, [primary key]) VALUES(@param1, @param2)

    Or this:

    UPDATE tbl SET whatever = @param1 WHERE [primary key] = @param2
    IF @@ROWCOUNT = 0
    INSERT tbl(whatever, [primary key]) VALUES(@param1, @param2)

    For Access, you would have to use a stored query (assuming those can handle
    multiple DML statements!) or perform two round-trips, but the logic would
    essentially be the same.

    Or, the previous page can have a flag that is passed, depending on whether
    someone chose "add" or "edit"...

    --
    Aaron Bertrand
    SQL Server MVP
    [url]http://www.aspfaq.com/[/url]





    "Michael Posthoff" <posthoff@e-confirm-quatsch.de> wrote in message
    news:c5ito9$mkb$1@news1.transmedia.de...
    > Hallo Group,
    >
    > is there an equivelant/replacement of the MySQL Command "Replace Into" for
    > Access/MS SQLServer?
    >
    > "Replace Into" does either inserting or updating of data, depending on
    > whether the record exists or not. And I would love to avoid 2 differnet
    > functions for this.
    >
    > regards,
    > Michael Posthoff
    >
    >
    >

    Aaron Bertrand [MVP] 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