mysqlsqlsql-serverwhere-clauseclrstoredprocedure

subtract year using Select Dateadd() sqlserver


I have 2 textboxes: expiredfrom and expiredto. These textboxes allow user to find people that are using license and will expired within a year after payment in a range from 'expired from' to 'expired to'. In my database, it only show the date of purchase, so Im trying to use SELECT DATEADD() function to subtract the user input by 1 year so the expired date will same as purchase date. However, when I try to implement, it shows that there is syntax error in it. What is the problem? thanks

(@ExpiredFrom IS NULL OR @ExpiredFrom = '' OR 
@ExpiredTo IS NULL OR @ExpiredTo = '' OR
db.[dbo].Subscription.PurchaseDate BETWEEN SELECT DATEADD(yyyy,-1, @ExpiredFrom) 
AND SELECT DATEADD(yyyy,-1,@ExpiredTo))

Solution

  • I would suggest you remove SELECT there. Simply BETWEEN DATEADD(yyyy,-1, @ExpiredFrom) AND DATEADD(yyyy,-1,@ExpiredTo))