如何将选择查询提供给Insert Query sqlserver [英] How can I give select query into Insert Query sqlserver

查看:74
本文介绍了如何将选择查询提供给Insert Query sqlserver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我必须将参数传递给insert,还有一些字段需要从其他表中选择和插入。



插入 TABLEA (不,名称, CName )值(@ ID,@ NAME, (选择 CNAME FROM TableB ,其中ID = 1)



这不行。还有其他解决方案吗?



请帮帮我...



谢谢&此致,



Vineetha



I have to pass parameters to insert and also some fields need to select and insert from other tables.

Insert into TABLEA (No,Name,CName) values (@ID,@NAME,(select CNAME FROM TableB where ID =1 ))

It's not work. Have any other solution for this?

Please help me...

Thanks & Regards,

Vineetha

推荐答案





试试这个...





Hi,

Try this...


Insert into TABLEA (No,Name,CName) 
SELECT @ID,@NAME,CNAME FROM TableB where ID =1





希望这会对你有所帮助。



干杯



Hope this will help you.

Cheers


insert-into-sql-server-table-with-select-command / [ ^ ]



http://technet.microsoft.com/en-in/library/ms188263%28v=sql.105%29.aspx [ ^ ]


请尝试这样,



Please try like this,

Insert into TABLEA (No,Name,CName) select @ID,@NAME,(select CNAME FROM TableB where ID =1 )





我认为它有效。



I Think it works.


这篇关于如何将选择查询提供给Insert Query sqlserver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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