0

Here I want to check that if a trip for a particular semester is arranged between from date to date in previous table records.

Table Schema:

trip_from_date
trip_end_date
trip_sem_id
trip_dress_code

Stored Procedure:

CREATE PROCEDURE [db].[pro_1] var duration, 
  @Trip_sem_id    int, 
  @Trip_from_date date, 
  @Trip_to_date   date 
AS 
  BEGIN 
    SELECT * 
    FROM   isrp_trip_master 
    WHERE  trip_sem_id=@Trip_sem_id 
    AND    duration BETWEEN trip_from_date=@Trip_from_date AND    trip_to_date=@Trip_to_date 
    AND    isnull(trip_is_delete,0)=0 
  END

I expect a table with all field which fulfills my condition

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786

2 Answers2

0

Assuming you have somehow already checked that trip_from_date < trip_to_date (CHECK constraint):

trip_from_date >= @Trip_From_date AND trip_to_date <= @Trip_to_date
FXD
  • 1,960
  • 1
  • 6
  • 9
0

To add more details from lau's answer are you expecting to do something like this

declare  @Trip_from_date date= '1 Jan 2018'
declare  @Trip_to_date   date = '23 Jan 2018'
--Check to see if the dates selected falls within the required range
select * from isrp_trip_master where @Trip_from_date >= trip_from_date and     trip_end_date >=@Trip_to_date`
Gnyasha
  • 658
  • 11
  • 19