How to write something like this in SQLite ? Like optional param if null don’t use.
(@Year IS NULL OR @Year = DATEPART(year, Date)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could do something like this:
IFNULL returns its first non-null argument. In this case, the query will compare
@YeartoDATEPART(year, Date)as long as@Yearis not null. If it IS null, then it’ll compareDATEPART(year, Date)toDATEPART(year, Date), which will always be true.Edit: Note that
DATEPARTis not a native SQLite method (the OP referenced it so it may be a custom thing he/she is using). A native solution is to usestrftime("%Y", Date)(Thanks @Jason!)