Need to copy records from one user to other user without deleting

  • HI

    I need to write a query/sp to transfer data of one user to another user.

    lets say user 1 has many rows in many tables, i can get the row and table list

    I have written a query which will transfer the data but it is cut and paste instead i want copy and paste.

    As of now i have written a cursor and im fetching table name and updating the records in table with user 2 name.

    what should i do to get copy n paste instead of cut n paste

  • It would be easier to answer your question if you provided the table schemas involved. See the links in my signature for how to post questions.

    Now on to an answer. I think you want duplicate a user. This code assumes user 2 already exists, but has no data associated with it.

    [font="Courier New"]INSERT INTO user_data

       SELECT

           2 AS userid,

           [other columns...]

        FROM

           dbo.user_data

       WHERE

           userid = 1

    [/font]

  • Hi i have a statement this way -

    @getTname - gets the list of tables

    EXEC ('UPDATE ' + @getTname + ' SET db_User_ID= ' + @toUserId + ' WHERE db_User_ID= ' + @fromUserID)

    Now i want the data should not be deleted from @fromuserid , also it should get copied to @touserid.

    Also if data is present in @touserid it should also be not deleted. New data should get appended to this

  • See code above from Jack Corbett.

    Is does everything you need and not using dynamic sql.


    N 56°04'39.16"
    E 12°55'05.25"

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

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