简体   繁体   中英

SQL Statement to copy rows of data

So i have a table with data that shows users and the assets they own. Each row is a different asset, so there is multiple rows for one user. Here's a sample row:

样本行

My question is what statement would I have to write to copy multiple rows of data from user 'AARONM' to user 'KODYM'? I believe I am over thinking it with the querys that I have tried, but I thought I would ask for outside help. Thank you in advance for your replies.

This is what I have right now:

 INSERT INTO Assets (USERNAME, ASSETTAG, 
    SERIALNUMBER, DEPT, CATEGORY, ITEMDESC, MODEL, ISSUEDATE, ISSUEDBY, 
    TOTALVALUE, ACCESSORIES, ISSUECONDITION, 
    NOTES, CREATEBY, CREATEDATE) 
    SELECT @USERNAME2, ASSETTAG, SERIALNUMBER, DEPT, CATEGORY, ITEMDESC, MODEL, 
    ISSUEDATE, ISSUEDBY, TOTALVALUE, ACCESSORIES, 
    ISSUECONDITION, NOTES, CREATEBY, CREATEDATE FROM ASSETS WHERE USERNAME = @USERNAME 

You would use insert . . . select insert . . . select insert . . . select :

insert into t(user, . . . )  -- list of columns here
    select 'KODYM', . . .  -- values for the other columns
    from t
    where user = 'AARONM';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM