朋友请帮助编写sql查询 [英] Friends Please Help In Writing Sql Query

查看:90
本文介绍了朋友请帮助编写sql查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,
我想从其RecieveTime在给定日期之间的DateBase访问电子邮件. 我只想匹配或比较日期部分..
我写了这个查询,但是及时出现了一些问题
我不想比较时间.
我正在使用Sql Server 2005和.net 2.0框架工作

Hi Friends ,
I Want to access Email from my DateBase whose RecieveTime Is Between given dates ..
I only want to match or compare the date part ..
I write this query but there is some problem in time
I dont want to compare time.
I am Using Sql Server 2005 and .net 2.0 Frame work

select * from OUTLOOK_DETAIL where  convert(datetime,'" + Program.datefrom + "')<=RECEIVE_TIME  and  convert(datetime,'" + Program.dateto + "')>=RECEIVE_TIME order by RECEIVE_TIME

推荐答案

在sql中使用BETWEEN运算符.

http://msdn.microsoft.com/en-us/library/ms187922.aspx [ ^ ]
Use the BETWEEN operator in sql.

http://msdn.microsoft.com/en-us/library/ms187922.aspx[^]


少量内容:
-使用绑定变量,请参见 SqlParameter [
Few things:
- use bind variables, see SqlParameter[^]
- use between operator

select * 
from OUTLOOK_DETAIL 
where RECEIVE_TIME BETWEEN @datefrom AND @dateto
order by RECEIVE_TIME


假定该程序.从& Program.dateto为"mm/dd/yyyy"格式,一种选择如下:

assuming that Program.datefrom & Program.dateto is in "mm/dd/yyyy" format, one option is as follows:

select * from
OUTLOOK_DETAIL
where  '" + Program.datefrom + "' <=  convert(varchar(10),RECEIVE_TIME,101) and  '" + Program.dateto + "' >= convert(varchar(10),RECEIVE_TIME,101) order by
RECEIVE_TIME



检查以下链接以了解其他选项:

http://weblogs.sqlteam.com/jeffs/archive/2004/12/02/2954.aspx [ ^ ]



check the following link for other options:

http://weblogs.sqlteam.com/jeffs/archive/2004/12/02/2954.aspx[^]


这篇关于朋友请帮助编写sql查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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