1

有一些值的表

role_number  action_number    status
   4               2            1
   4               5            0
   4               8            1
   4               7            0
   4               10           1
   4               3            0

现在想要新的 role_number 具有相同的 action_number 和 status ,如何插入它?例如它必须是这样的:

  role_number  action_number    status
       4               2            1
       4               5            0
       4               8            1
       4               7            0
       4               10           1
       4               3            0
       5               2            1
       5               5            0
       5               8            1
       5               7            0
       5               10           1
       5               3            0
4

5 回答 5

1

这是使用 INSERT/SELECT 的可能解决方案:

INSERT INTO YourTable(role_number, action_number, status)
SELECT @NewRoleNumber, action_number, status
FROM YourTable
WHERE RoleNumber = @RoleNumberToBeCopied
于 2013-11-11T13:01:51.670 回答
1
INSERT INTO YourTable
    (role_number, action_number, status)
SELECT role_number + 1, action_number, status
FROM YourTable
WHERE role_number = 4
于 2013-11-11T13:02:52.723 回答
0
INSERT INTO [tablename] (role_number, action_number, status)
SELECT 5, action_number, status FROM [tablename] where role_number = 4
于 2013-11-11T13:01:35.657 回答
0

只需从同一个表中插入

INSERT INTO TableName
SELECT MAX(role_number)+1, action_number, status FROM TableName WHERE role_number = 4
于 2013-11-11T13:01:51.013 回答
0
DECLARE @oldRollNo int = 4,
        @newRollNo int = 5;
INSERT INTO tablename (role_number, action_number, status)
SELECT @newRollNo, action_number, status FROM tablename where role_number = @oldRollNo
于 2013-11-11T13:10:19.417 回答