复制用户描述并添加具有相同描述的新用户
Copy User Description and add new User with the same Description
我有这个 table UserInfo
UserInfo
-------------------------------------
UserID FirstName,LastName, Description
--------------------------------------
1 Kevin Love Forward
2 Stephen Curry Guard
我想在同一个 table 上复制 UserID 2 Description
,但新用户使用新用户 ID
我有两个页面:
UserList 页面 - 显示 UserInfo 中的所有记录,并有一个选项
Copy
将在选定用户上复制 Description
并将
重定向到我的第二页 'CopyInfo'.
CopyInfo 页面 - 将仅显示并询问用户新的 Firstname, LastName
和选定的
UserID 2
Description
.
输出:
UserInfo
-------------------------------------
UserID FirstName,LastName, Description
--------------------------------------
1 Kevin Love Forward
2 Stephen Curry Guard
3. Steve Kerr Guard
请帮忙。谢谢!
假设 UserID is an IDENTITY
并且您正在使用 SQL2005 and later
,您可以使用以下查询:
with ct as (
select [Description] from UserInfo
where UserID = 2
)
insert into UserInfo (FirstName, Lastname, Description)
values ('Steve', 'Kerr', ct.Description)
如果 UserID is not IDENTITY
,您需要在 INSERT
语句中为它提供一个值
我有这个 table UserInfo
UserInfo
-------------------------------------
UserID FirstName,LastName, Description
--------------------------------------
1 Kevin Love Forward
2 Stephen Curry Guard
我想在同一个 table 上复制
UserID 2 Description
,但新用户使用新用户 ID我有两个页面:
UserList 页面 - 显示 UserInfo 中的所有记录,并有一个选项
Copy
将在选定用户上复制Description
并将 重定向到我的第二页 'CopyInfo'.CopyInfo 页面 - 将仅显示并询问用户新的
Firstname, LastName
和选定的UserID 2
Description
.
输出:
UserInfo
-------------------------------------
UserID FirstName,LastName, Description
--------------------------------------
1 Kevin Love Forward
2 Stephen Curry Guard
3. Steve Kerr Guard
请帮忙。谢谢!
假设 UserID is an IDENTITY
并且您正在使用 SQL2005 and later
,您可以使用以下查询:
with ct as (
select [Description] from UserInfo
where UserID = 2
)
insert into UserInfo (FirstName, Lastname, Description)
values ('Steve', 'Kerr', ct.Description)
如果 UserID is not IDENTITY
,您需要在 INSERT
语句中为它提供一个值