简体   繁体   中英

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))

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM