Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.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 使用单Insert语句插入_Sql_Sql Server 2005_Tsql_Insert Update - Fatal编程技术网

Sql 使用单Insert语句插入

Sql 使用单Insert语句插入,sql,sql-server-2005,tsql,insert-update,Sql,Sql Server 2005,Tsql,Insert Update,我想在tblSubscriptions表中插入数据,我只想使用一条insert语句。 我将为用户表中的每个用户ID插入数据。以下SQL不起作用 Insert tblSubscriptions (UserID, ProductID, isACtive, SubscriptionDays, Price, MonthlyPrice, ProductType, CurrencyID) Values ((Select userID From tblUser where SubscriptionType i

我想在tblSubscriptions表中插入数据,我只想使用一条insert语句。 我将为用户表中的每个用户ID插入数据。以下SQL不起作用

Insert tblSubscriptions (UserID, ProductID, isACtive, SubscriptionDays, Price, MonthlyPrice, ProductType, CurrencyID)
Values ((Select userID From tblUser where SubscriptionType in(1, 0, null)), 7, 1, 0, 0, 0, 30, 1)
如何使用一条insert语句(即不使用游标)执行此操作。

只需删除“值”

INSERT(...)
SELECT ...
只需删除“值”

INSERT(...)
SELECT ...
查询 查询 IN子句不能与NULL一起使用


IN子句不能与NULL一起使用

我会尝试这个和接受的答案。我怀疑如果有一个大的数据集,这个数据集的性能可能会更好。我会尝试这个和公认的答案。我怀疑如果有一个大的数据集,这个数据集的性能可能会更好。
Insert tblSubscriptions (UserID, ProductID, isACtive, SubscriptionDays, Price, MonthlyPrice, ProductType, CurrencyID)
Select userID, 7, 1, 0, 0, 0, 30, 1
From tblUser where SubscriptionType in (1, 0) or SubScriptionType is null