sql - stored procedure return return more than 1 value -


alter procedure [dbo].[sp_checktime] ( @booking_date date ,     @stime time(7) ,     @etime time(7) ,     @room varchar(50),     @res int output  ) begin if (@stime=(select start_time booking_master booking_date=@booking_date , room=@room) or @stime>=(select start_time booking_master) , @stime<=(select end_time booking_master booking_date=@booking_date , room=@room)) begin         set @res=0 end  else         begin         set @res=1     end  end 

when excuting procedure reurns (subquery returned more 1 value. not permitted when subquery follows =, !=, <, <= , >, >= or when subquery used expression.)

the immediate cause problem statement:

@stime=(select start_time booking_master booking_date=@booking_date , room=@room) 

the subquery seems return more 1 row. "reflexive" fix replace in:

@stime in (select start_time booking_master booking_date=@booking_date , room=@room) 

in case, think better off fixing logic have 1 if (exists . . .) statement. like:

if (exists (select 1             booking_master bm             booking_date = @booking_date , room = @room ,                   (@stime = start_time or                    (@stime >= starttime , @stime <= endtime)                   )            )    ) 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -