[英]How to copy values from table for another column
have table with some values 有一些值的表
role_number action_number status
4 2 1
4 5 0
4 8 1
4 7 0
4 10 1
4 3 0
Now want new role_number with same action_number and status , how to insert it ? 现在想要具有相同action_number和status的新role_number,如何将其插入? for example it must be like :
例如,它必须像:
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
Here it is a possible solution using INSERT/SELECT: 这是使用INSERT / SELECT的可能解决方案:
INSERT INTO YourTable(role_number, action_number, status)
SELECT @NewRoleNumber, action_number, status
FROM YourTable
WHERE RoleNumber = @RoleNumberToBeCopied
INSERT INTO YourTable
(role_number, action_number, status)
SELECT role_number + 1, action_number, status
FROM YourTable
WHERE role_number = 4
INSERT INTO [tablename] (role_number, action_number, status)
SELECT 5, action_number, status FROM [tablename] where role_number = 4
Just insert from the same table 只需从同一张表插入
INSERT INTO TableName
SELECT MAX(role_number)+1, action_number, status FROM TableName WHERE role_number = 4
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.