本文介绍了在SQL Server中的两个日期之间以及从单列或双列中检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我有两个varchar数据类型字段来存储简单日期.我知道没有一种在varchar中存储日期的好方法,但是由于某种错误,它占用了它,现在插入了很多数据.

我有2列,例如1. From date和2.迄今为止

如果我有类似
的数据
起始日期|迄今为止
----------------------------------
1. 2012/08/06 2012/08/06
2. 2012/08/06 2012/08/09
3. 2012/08/05 2012/08/09


如果执行此日期与2012/08/06和2012/08/06的查询,我想要的两个结果像1和2,因为第二个包含相同的日期.迄今为止仍然相同.

所以,我该怎么做到..

我使用但未获得完美结果....

Dear All,

I have two fields of varchar datatype to store the simple date. i know there is not good way to store date in varchar but by some mistake it taken it and lots of data inserted now.

I have 2 column like 1. From date and 2 . To date

if i have data like

From Date | To Date
----------------------------------
1. 2012/08/06 2012/08/06
2. 2012/08/06 2012/08/09
3. 2012/08/05 2012/08/09


if execute the query with 2012/08/06 and 2012/08/06 this dates, the two result i want to come like 1 and 2 because the second one containt the same date. ans same for to date.

so, how can i achive this ..

i use but not getting the perfct result....

select leave_id,date_of_leave,from_name,dept,from_date,to_date,total_days,reason,report_to_whom from leave_record inner join empl on leave_record.from_name=empl.name  where convert(datetime,leave_Record.date_of_leave,103) between ''2012/08/06'' and ''2012/08/09'' order by convert(datetime,leave_record.from_date,103) desc




谢谢和问候,
MItesh




Thanks and Regards,,,
MItesh

推荐答案

select leave_id,date_of_leave,from_name,dept,from_date,to_date,total_days,reason,report_to_whom
from leave_record
inner join empl on leave_record.from_name=empl.name
where convert(datetime,convert(varchar(10),leave_Record.date_of_leave,102)) between '2012/08/06' and '2012/08/09' order by convert(datetime,convert(varchar(10),leave_record.from_date,102)) desc


祝您编码愉快!
:)


Happy Coding!
:)


这篇关于在SQL Server中的两个日期之间以及从单列或双列中检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 17:45