Java SQL Server 2008中的子选择查询错误

Java SQL Server 2008中的子选择查询错误,java,sql-server,sql-server-2008,jdbc,Java,Sql Server,Sql Server 2008,Jdbc,考虑以下查询: insert into dbo.SubscriptionDetails (taxonomyid) values(select objectid from SubscriptionObjects where objectname=?) 此查询在本地环境中运行良好,但在生产环境中执行时会出现问题 子选择查询是否需要在SQL Server级别设置任何属性 我使用Java-JDBC进行SQL事务 请参见下面的堆栈跟踪: 2013.03.28 15:42:11 CDT ERROR Er

考虑以下查询:

insert into dbo.SubscriptionDetails (taxonomyid) 
values(select objectid from SubscriptionObjects where objectname=?)
此查询在本地环境中运行良好,但在生产环境中执行时会出现问题

子选择查询是否需要在SQL Server级别设置任何属性

我使用Java-JDBC进行SQL事务

请参见下面的堆栈跟踪:

2013.03.28 15:42:11 CDT ERROR Error while inserting records into SubscriptionDetails table..
java.sql.BatchUpdateException: Subqueries are not allowed in this context. Only scalar expressions are allowed.

我很惊讶你的版本能在任何环境下工作!尝试忽略值:

对于多个子查询,您可以:

insert  into dbo.SubscriptionDetails 
        (taxonomyid, contenttypeid) 
select  (select objectid from SubscriptionObjects where objectname=?)
,       (select objectid from SubscriptionObjects where objectname=?)
或者,使用括号强制使用标量上下文值:


抱歉,这是一个单一的插入查询。。。select是insert查询的一部分。@TeeGee:当您运行此查询时,是否遇到错误或是什么?@Quassnoi-是的,我知道,请参阅附件StackTrace。我的产品可能与生产环境中的数据有关。谢谢这正是我在Java中使用的准备好的语句。。。它是有效的。在dbo.SubscriptionDetails中插入userid、eventid、taxonomyid、contenttypeid、typeid值?、?,+从subscriptionObject中选择objectid,其中objectname=?,+从SubscriptionObject中选择objectid,其中objectname=?,+?@和OMAR您能解释一下强制标量上下文的含义吗?为什么会出现这种错误?
insert  into dbo.SubscriptionDetails 
        (taxonomyid, contenttypeid) 
select  (select objectid from SubscriptionObjects where objectname=?)
,       (select objectid from SubscriptionObjects where objectname=?)
insert  into dbo.SubscriptionDetails 
        (taxonomyid, contenttypeid) 
values  ((select objectid from SubscriptionObjects where objectname=?),
         (select objectid from SubscriptionObjects where objectname=?))