user3279082
user3279082

Reputation:

Setting dynamic values for dropdown filters

I have a gridview and a dropdown filters in the page. Also I have a date column in gridview which has values like 2014-04-12 and 2014-04-25. Assuming the current budget year if someone adds a row with the year 2016 and when I filter the dropdown I have exclude that 2016 columns using this below query.

Query:

select ID, Group,CONVERT(Date, Summary_Date) as Summary_Date from Application where  Group='" + selectedGroup + "' and Summary_Date <='2015-01-01' order by ID, Summary_Date

Now this query will work only for current budget year. And if we have moved to next budget year I have to exclude rows which has 2017 rows and how can I handle that dynamically. Anyone pls let me know for further clarity?

Upvotes: 1

Views: 107

Answers (1)

gkrishy
gkrishy

Reputation: 756

You can use DateAdd function instead of manual work.

If am not wrong, you can change your query like this,

select ID, Group,CONVERT(Date, Summary_Date) as Summary_Date from Application where  Group='" + selectedGroup + "' and Summary_Date <=Dateadd(year,1,getdate()) order by ID, Summary_Date

Here it will add automatically one year from your current year. For eg : in the case of 2014, query will filter the records within 2015. Same as 2016,2017 etc.,

For further clarification about DateAdd, please Click Here

Upvotes: 1

Related Questions