Create View - with Date in sorted order (in Short Date format type) (1 Viewer)

Rx_

Nothing In Moderation
Local time
Yesterday, 20:27
Joined
Oct 22, 2009
Messages
2,803
Before anyone responded, I just removed the Converts.
With a ODBC connection to the View, I kind of expected the sort orders to be valid.
Since they are not, I will manage this at the VBA level.

Let the lesson be that a Convert (varchar....) does exactly that as advertised.
While the linked table of a view is much faster than passing a SQL statement, it appears that Access SQL must be used to obtain the date order.
From SQL, the view results appears in the correct order.
It appears that something is lost in the ODBC (SQL Native Client) layer.


What function in T-SQL or MS SQL will keep the date format, but not show the time portion of the date - so the view can be sorted by date on one column?
This conversion prevents sorting by Year-Month-Date
A set of data has dates that need to be sorted by date on one field.
A View was created. The view becomes a Linked Table in Access.
The dates all had the full time format for the date and hour format.
e.g. 5/9/14 12:00PM
Only the date was needed. So the CONVERT function was used. At first appearance, it seemed to make a short date format: e.g. 01/11/2014
But, the sort is all on the first two characters (the day for us US types) instead of the actual date.

The linked tables show the format as Text.

Code:
SELECT     TOP (100) PERCENT ID_Wells, txtFedStCo AS RE_24Type, CONVERT(varchar, Dt_APD_Sub, 101) AS RE_24DTSub, txt_APD_Apv_Status AS RE_24Status, 
                      CONVERT(varchar, Dt_APD_Apv, 101) AS RE_24DTApp, CONVERT(varchar, Dt_APD_Exp, 101) AS RE_24DTExp, CONVERT(varchar, Dt_APD_WithDrawn_Sub, 101) 
                      AS RE_24DTWDSub, CONVERT(varchar, Dt_APD_WithDrawn_APProved, 101) AS RE_24DTWDApp
FROM         dbo.tblAPD_Fed_ST_CO
WHERE     (txtFedStCo IN (N'Fed')) AND (txt_APD_Apv_Status = N'Approved') AND (NOT (CONVERT(varchar, Dt_APD_Sub, 101) IS NULL))
ORDER BY ID_Wells, RE_24DTSub DESC
 

Attachments

  • Convert doesn't sort by Year-Date-day.png
    Convert doesn't sort by Year-Date-day.png
    32 KB · Views: 160
Last edited:

Rx_

Nothing In Moderation
Local time
Yesterday, 20:27
Joined
Oct 22, 2009
Messages
2,803
Got a short break to take SnagIT of the SQL Server View side-by-side the MS Access Linked Table

The point is that a SQL View will appear differently in the Access Linked table in 2 ways.

1. The SQL View shows the Date and Time. Access shows only the date, however it is a Date data type so the time could be extracted if needed.

2. The Access results totally disregards any SQL Server sorts.
The ID_Wells column was completely random until manually sorted for this demo.

Hope this will be useful information for someone else.
 

Attachments

  • SQL Server View with Cooresponding Access Linked Table.jpg
    SQL Server View with Cooresponding Access Linked Table.jpg
    104.4 KB · Views: 271

Users who are viewing this thread

Top Bottom