Sql 使用单Insert语句插入
我想在tblSubscriptions表中插入数据,我只想使用一条insert语句。 我将为用户表中的每个用户ID插入数据。以下SQL不起作用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
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