将值从一个表插入到另一个表中,也可以使用变量 - 通过存储过程 [英] Insert value From One Table to Another and also with variable- via Store Procedure

查看:86
本文介绍了将值从一个表插入到另一个表中,也可以使用变量 - 通过存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Store Store中的新手。

我有一个Store Procedure,可以在运行时从客户端插入值,也可以从另一个表的ID列插入值。我的SP持有3栏:

SId

名称

Addess



现在如何从两个区域插入(ID和名称列中的用户输入和另一个表中的地址)?

先谢谢。

I am New in Store Procedure.
I have a Store Procedure to insert values from client at runtime and also from another table's ID column. My SP holds 3 Column:
SId
Name
Addess

Now How to insert from both area(User Input in ID and Name column and Address is From another table)?
Thanks in Advance.

推荐答案

INSERT INTO insertTable (x, y, z)
SELECT x, y, z
FROM a INNER JOIN b ON a.id = b.id





此格式可以正常使用。使用连接执行Sql并在顶部添加第一行以插入它。







This format will work fine. Do the Sql with the join and add the first line at the top to make an insert of it.


create table t1
( 
  id int,
  val varchar(5),
  dt datetime
)


create table t2 
(
  id int,
  val varchar(5)  
)

insert into t2 values(1,'test')
insert into t2 values(2,'check')

insert into t1
select id, val, getdate() from t2

select * from t1





这将输出:



1 test 2013-12-30 21:17:42.117

2 check 2013-12-30 21:17:42.117



随时随地都有。您可以使用您的参数替换getdate(),换句话说,您需要做的就是将它们添加到选择列表中,这将按照您的要求运行。



This will output:

1 test 2013-12-30 21:17:42.117
2 check 2013-12-30 21:17:42.117

with what ever the time is there. You can replace getdate() with your parameters, in other words, all you need to do, is add them to the select list and this will work as you asked.


这篇关于将值从一个表插入到另一个表中,也可以使用变量 - 通过存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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