Incorrect SQL query when export data using an Advanced find date query

Just spotted an interesting bug with a query I was running using Advanced find.
My query was display all opportunities that are open and closing in the next 4 months. The results were returned correctly via the advanced find search, but when I exported the data the SQL definition was incorrect.
The original query  string looked like this:
where ((opportunity0.statecode = 0 and  opportunity0.estimatedclosedateutc >= dbo.fn_NextXMonth(GetUTCDate(), 4) and opportunity0.estimatedclosedateutc < GetUTCDate() ))
If you notice the >= and second < are the worng way around, the query should of looked like this:
where ((opportunity0.statecode = 0 and  opportunity0.estimatedclosedateutc < dbo.fn_NextXMonth(GetUTCDate(), 4) and opportunity0.estimatedclosedateutc > GetUTCDate() ))
Notice also I removed the first = as SQL interprets dates as Date Time and not just Date so my returned results included records that fell out the date range.
So my workaround was to manually update the SQL definition in my excel report and save this as a standard report.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s