public static string BuildFilterForDateInsideInterval(string dateAlias, string startParameter, string endParameter)
{
var filter = @"
(
(
(NOT {0} IS NULL) AND
(NOT {1} IS NULL) AND
(NOT {2} IS NULL) AND
(TRUNC({0}) >= TRUNC({1})) AND
(TRUNC({0}) <= TRUNC({2}))
) OR
(
(
({0} IS NULL)
) OR
(
({1} IS NULL) AND
({2} IS NULL)
) OR
(
(NOT {0} IS NULL) AND
({1} IS NULL) AND
(TRUNC({0}) <= TRUNC({2}))
) OR
(
(NOT {0} IS NULL) AND
({2} IS NULL) AND
(TRUNC({0}) >= TRUNC({1}))
)
)
)
";
var mergedFilter = string.Format(filter.TrimInternalSpacesAndLineFeeds(), dateAlias, startParameter, endParameter);
return mergedFilter;
}