How to use DateTime in a SqlFilter with .NET
Have you been wondering how to use DateTime inside of SqlFilters, with your Topics/Subscriptions? Have you also noticed that this doesn't seem to work?
var message = new BrokeredMessage();
message.Properties["datetime"] = DateTime.Now;
var sqlFilter = new SqlFilter("datetime > '2016-06-06'");
That's because you explicitly need to add the DateTime as a parameter, like so:
var filter = new SqlFilter(" datetime >= @datetime");
filter.Parameters.Add("@datetime", DateTime.Parse("2016-06-06"));
In order to make this more searchable in the future, I have also added a corresponding StackOverflow question: https://stackoverflow.com/questions/37705333/azure-service-bus-using-datetime-in-topic-subscription-sqlfilter-in-net
Comments
- Anonymous
June 08, 2016
Great info John, thank you.Do you think it would be good to have this kind of info at https://msdn.microsoft.com/library/azure/microsoft.servicebus.messaging.sqlfilter.sqlexpression.aspx as well?- Anonymous
June 16, 2016
Thanks for the note Sean! We added an example using dates to the MSDN page.
- Anonymous
- Anonymous
July 05, 2016
One more thing: If you have a single filter like that, it's ok. If you have multiple filters, the current limitation of parameters/subscriptions makes it almost impossible to maintain. Parameter values are not discoverable. Looking at a filter once it's created, one cannot not know what't the value that parameter represents. I've raised an issue about this. Should be somewhere on the backlog (hopefully) :)