读书人

子查询有关问题

发布时间: 2012-02-09 18:22:27 作者: rapoo

子查询问题
当执行
if (@last1+@last2)%10=6 and ((select P3 from xue where id=@idN) in (6,7))
显示

消息 512,级别 16,状态 1,第 111 行
子查询返回的值不止一个。当子查询跟随在 =、!=、 <、 <=、> 、> = 之后,或子查询用作表达式时,这种情况是不允许的。
==================

我理解是不能使用in
请教简单的修改,使其可运行和达到原来代码用途。

[解决办法]
if (@last1+@last2)%10=6 and ( exists (select 1 from xue where id=@idN and P3 in(6,7)) )

读书人网 >SQL Server

热点推荐