Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

for my banking application i have a table called SCHEME

in that Scheme table i have fields as

From_date , To_date

from page i will insert only the From_date only , then To_date is stored as NULL in the table.

here i want to check From_date between From_date and To_date.

i written the following query but due to To_date is null the condition is fail.
SQL
SET @X_Valid =(SELECT COUNT(*) FROM scheme_valid
WHERE ( @From_Date between From_Date and To_Date
        or  @To_Date between From_Date and To_Date
        or  From_Date between @From_Date and @To_Date
        or  To_Date between @From_Date and @To_Date
      )                       
AND   Scheme_ID=@L_id)
Posted
Updated 17-Oct-12 3:57am
v2

Check for
SQL
NOT IsNull(To_date) AND (...)
 
Share this answer
 
Try this code..

SQL
SET @X_Valid =(SELECT COUNT(*) FROM scheme_valid
WHERE   ((From_Date >= @From_Date) or (@From_Date IS NULL)
        AND
        (To_Date <= @To_Date) or (@To_Date IS NULL))
        AND   Scheme_ID=@L_id)


please rate answer if it is useful...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900