Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 插入多模块行单次插入查询_Sql_Sql Server 2008_Insert_Sql Server 2008 R2_Multiple Records - Fatal编程技术网

Sql 插入多模块行单次插入查询

Sql 插入多模块行单次插入查询,sql,sql-server-2008,insert,sql-server-2008-r2,multiple-records,Sql,Sql Server 2008,Insert,Sql Server 2008 R2,Multiple Records,第一个查询我得到的用户id记录如下: 1 14 22 38 39 54 68 74 INSERT INTO tbl_Channel_Subscriber(user_id,channel_id,status,EntDate) VALUES(@user_id,@channel_id,@status,@EntDate). 现在,我想在单个查询的另一个表中插入上述用户id,如下所示: 1 14 22 38 39 54 68 74 INSERT INTO tbl_Channel_Subscriber

第一个查询我得到的用户id记录如下:

1
14
22
38
39
54
68
74
INSERT INTO tbl_Channel_Subscriber(user_id,channel_id,status,EntDate) VALUES(@user_id,@channel_id,@status,@EntDate).
现在,我想在单个查询的另一个表中插入上述用户id,如下所示:

1
14
22
38
39
54
68
74
INSERT INTO tbl_Channel_Subscriber(user_id,channel_id,status,EntDate) VALUES(@user_id,@channel_id,@status,@EntDate).

如何使用单次插入查询插入新记录

不要使用两次查询。一次完成并将变量添加到第一个查询中

INSERT INTO tbl_Channel_Subscriber(user_id,channel_id,status,EntDate) 
select user_id, @channel_id, @status, @EntDate
from first_table

读取值后使用循环插入可能重复的juergen,并从tbl\u Followers中选择DistinctOutser\u id,其中用户id插入从tbl\u Followers中选择DISTINCTfollowers\u id,其中用户id=14且状态为“follower”,或用户id从tbl\u Followers中选择DistinctOutser\u id,其中用户id=14且状态为“follower”。此查询我正在获取用户id,如何将此查询插入tbl_Channel_Subscriberuser_id、Channel_id、status、EntDateSELECT DISTINCTuser_id、@Channel_id、@status、,@EntDate FROM tbl_Following_Following_Following_Following_id FROM tbl_Following_Following_Following_user_id=14且status='Following'或user_id INSELECT DISTINCTuser_id FROM tbl_Following_Following_Following_Following_Following_在给定查询中成功插入记录,但有些记录未插入意味着如果不同的用户id影响1,3,21,32,39,但仅插入两个或三个记录,则仅插入