选择插入替换列的局部变量
我想将一个表中的记录插入到另一个表中,
Insert into table2([column1], [column2], [column3])
select column1, column2, column3
from table1
但是我想插入存储在变量中的特定值,而不是来自表一的所有三个值。我认为它看起来像这样这样
declare @variable int
set @variable = 2
Insert into table2([column1], [column2], [column3])
select @variable, column2, column3
from table1
,表一中的每一行都会插入到表二中,唯一的区别是第一列中的每个值都是 2。
如果不使用游标,这可能吗?
I want to Insert records from one table into another like
Insert into table2([column1], [column2], [column3])
select column1, column2, column3
from table1
however instead of all three values coming from table one I would like to insert a specific value stored in a variable. I Think it would look something like this
declare @variable int
set @variable = 2
Insert into table2([column1], [column2], [column3])
select @variable, column2, column3
from table1
In this way every row from table one would be inserted into table two with the only difference being every value in column one would be 2.
Is this possible without using a cursor?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你这样做的方式是正确的:
The way you've done it is correct:
你所拥有的应该可以正常工作
what you have should work just fine