This bug appears on Microsoft SQL Server. I used Views + Date Views for filtering content by date range taken from URL arguments and got the following error:
SQLSTATE[42000]: [Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near '\'.
The sample query is:
SELECT node.[title] AS [node_title], node.[nid] AS [nid], node.[language] AS [node_language], node.[created] AS [node_created], 'node' AS field_data_field_event_date_node_entity_type
FROM
{node} node
LEFT JOIN {field_data_field_event_date} field_data_field_event_date ON node.nid = field_data_field_event_date.entity_id AND (field_data_field_event_date.entity_type = 'node' AND field_data_field_event_date.deleted = '0')
WHERE ( (( ([node].[status] = '1') AND ([node].[type] IN ('event_on_annual_calendar')) AND (DATEPART(yyyy-mm-dd\Thh:mi:ss, CAST(field_data_field_event_date.field_event_date_value2 as smalldatetime)) >= '2011-11-25T00:00:00' AND DATEPART(yyyy-mm-dd\Thh:mi:ss, CAST(field_data_field_event_date.field_event_date_value as smalldatetime)) <= '2011-11-25T00:00:00') )) )
ORDER BY node_created DESC
MSSQL cannot take date format strings in the DATEPART function (e.g. 'yyyy-mm-dd'), only separate identifiers for year, month, day etc.
I need this functionality and work on patch now. Any help on possible solutions will be greatly appreciated.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | mssql-date-formatting-fix-1352486-0.patch | 4.67 KB | d.novikov |
| view-export.txt | 9.56 KB | d.novikov |
Comments
Comment #1
d.novikov commentedI've noticed new fixes for Microsoft SQL date formatting in the latest dev but they seem to be incomplete. In addition MSSQL doesn't apply any formatting in DATEPART and DATENAME functions (e.g. 'year' doesn't differ from 'yyyy' and 'yy'; anyway it will return 'yyyy' format). I developed a version based solely on SQL. It can apply any format strings and doesn't need extra PHP wrappers. Patch is created against the current dev version.
The drawback of this patch are rather big and probably low queries.
Comment #2
d.novikov commentedPosted a new topic about the problem to the Drupal 8 core issue queue. Please share your thoughts if you want: http://drupal.org/node/1360656
Comment #3
web360 commentedWorks great.
Tested with date and time granularity in Views.
Installation profile: Drupal 7.9, Date 7.x-2.0-alpha4 ( with patches ), Views 7.x-3.0-rc1, running on Windows Server 2008 R2, IIS 7.5, MS SQL 2008.
Comment #4
karens commentedOK, I committed this. It looks more well thought out than the previous code.