你可以在不使用值@的情况下在语句中构建一个select insert [英] Can you build an select insert into statement without using the values@

查看:51
本文介绍了你可以在不使用值@的情况下在语句中构建一个select insert的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以在我的发言中我有:



so in my statement I have:

Select first_name from [table1] insert into [table2] (ID, First_name) values (@ID, @first_name)





但如果我以这种方式使用代码,我必须将值放入addwithvalue @ID和@first_name。



我想要做的就是将信息从一张桌子复制到另一张桌子。



我该怎么做才能解决这个问题?



我尝试过的方法:



我一直在使用参数,但我不确定我能用这种语句做到这一点。我已经尝试了一个datareader,但它只提供单个值,我需要复制所有这些并将其传输到另一个表。



but if I use the code this way I have to place values into addwithvalue @ID and @first_name.

All I want to do is copy information from one table to the other.

what can I do to remedy this?

What I have tried:

I have been using parameters, but I am not sure that I can do that with this type of statement. I have tried a datareader but it's only giving single values where I need to copy all this and transfer it to another table.

推荐答案

是的,你可以!

Yes you can !
SELECT * INTO newtable [IN externaldb]
FROM oldtable
WHERE condition;


INSERT INTO [table2] (ID, First_name)
SELECT id, first_name FROM [table1]


这篇关于你可以在不使用值@的情况下在语句中构建一个select insert的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆