使用Access 2010与SQL Server 2008以文本格式进行日期查询 [英] Date query when in text format using Access 2010 with SQL Server 2008

查看:76
本文介绍了使用Access 2010与SQL Server 2008以文本格式进行日期查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我使用Access 2010作为SQL Server 2008上数据库的前端。我有一个日期字段,存储为
nvarchar(50)。我在文本字段中有以下值DateHr  12/04/11
16:49:23
 ,应转换为  April
11,2012
4:49 PM
 (与创建记录的日期和时间相同。)。

I am using Access 2010 as a front-end to a database on SQL Server 2008. I have a date field which is stored as a nvarchar(50). I have the following value in the text field DateHr 12/04/11 16:49:23 , which should translate to April 11, 2012 4:49 PM (As is the date and time the record was created.).


我无法将字段的数据类型更改为DateTime,因为它会使日期更加混乱( Ex。
12/4/2011 4:49: 23 PM
)。我无法改变输入记录的方式。

I cannot change the datatype of the field to DateTime as it messes up the dates even more (Ex. 12/4/2011 4:49:23 PM). I cannot change the way the record is entered.


我需要以"mm / dd / yy"格式显示此字段,并且能够在此处执行 where
子句格式。


我在Access中尝试了以下内容,看看它是否显示正确,但是dtDate正在显示  11/12/04

Select (Format(CDate([DateHr]),"yy/mm/dd")) as dtDate

这显示正确但不容易查询日期。 />

This displays correctly but not easy to query date.

Select Format(DateSerial(Mid([DateHr],7,2),Mid([DateHr],4,2),Mid([DateHr],1,2)),"MM/DD/YYYY") as dtDate








我甚至尝试使用以下内容创建一个SQL Server Computed字段:  CONVERT(VARCHAR(20),
CAST('20'+ DateHr AS datetime))


完美显示,但由于Access将链接表字段视为文本而不是日期时间,因此很难在一系列日期之间进行搜索。

which displays perfectly, but am having a hard time trying to search between a range of dates as Access sees the linked table field as text instead of datetime.



我们非常感谢任何帮助。

Any help would be greatly appreciated.







推荐答案

嗨Rick131,

Hi Rick131,

>>甚至尝试使用以下内容创建SQL Server Computed字段:CONVERT(VARCHAR(20),CAST('20'+ DateHr AS datetime))

,显示完美,但是我很难在一系列日期之间进行搜索,因为Access将链接的表格字段视为文本而不是日期时间。

您可能拥有尝试使用参数在SQL Server中创建存储过程。在此存储过程中,您可以将参数转换为可在T-SQL中使用的格式。之后,可以在
上调用存储过程。带有必需参数的MS Access。

>> have even tried creating a SQL Server Computed field with the following: CONVERT(VARCHAR(20), CAST('20' + DateHr AS datetime))
which displays perfectly, but am having a hard time trying to search between a range of dates as Access sees the linked table field as text instead of datetime.
You may have a try to create a stored procedure in SQL Server with parameters. Within this stored procedure, you can convert parameters to the format which can be used in T-SQL. After that, it is possible to call the stored procedure on the MS Access with required parameters.

如果要在Access上实现转换,在开发人员访问
论坛。

If you want to achieve the conversion on the Access, it is more helpful to open a thread in Access for Developers forum.


这篇关于使用Access 2010与SQL Server 2008以文本格式进行日期查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆