我有一個存儲過程select * from book table
,使用子查詢我的查詢是子查詢返回多個值。當子查詢遵循=,!=,<,<=,>,> =或當子查詢用作表達式時,這是不允許的。
USE [library]
GO
/****** Object: StoredProcedure [dbo].[report_r_and_l] Script Date: 04/17/2013 12:42:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[report_r_and_l]
@fdate date,
@tdate date,
@key varchar(1)
as
if(@key='r')
select *
from dbo.books
where isbn =(select isbn from dbo.lending where (act between @fdate and @tdate) and (stat ='close'))
else if(@key='l')
select *
from dbo.books
where isbn =(select isbn from dbo.lending where lended_date between @fdate and @tdate)
我知道子查詢是返回多個查詢主要查詢,但我不知道如何避免這個錯誤,任何人都可以幫助我嗎?
顯然'select isbn'返回多個值。你可以使用'where isbn IN(select isbn ...' –