在sql server 2008中选择问题 [英] Problem in select in sql server 2008
本文介绍了在sql server 2008中选择问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的数据库中,我有一个表格,其中有一个日期时间字段
当我插入数据时,它包括时间与日期
i我面临选择数据的问题任何特定的
日期
在'08 / 01/2014'和'08 / 01/2014'之间说date1
我的查询是
In my database i have a table which has a datetime field
when i am inserting data it is including time with date
i am facing problem in selecting the data of any specific
date
Say date1 between '08/01/2014' and '08/01/2014'
my query is
SELECT *, (case when entrytype=0 or entrytype=3 then amount else 0 end )as Dmt
,(case when entrytype=1 or entrytype=2 or entrytype=4 or entrytype=66
then amount else 0 end )as cmt FROM FeesLedger
WHERE EntryDate
BETWEEN '01/08/2014' AND '01/08/2014'
AND StudentId = 2 AND Amount > 0 ORDER BY EntryDate,EntryNumber
推荐答案
首先,请阅读我对该问题的评论。
查看您的WHERE语句:
First of all, please, read my comment to the question.
Have a look at your WHERE statement:
WHERE EntryDate BETWEEN '01/08/2014' AND '01/08/2014'
2件事:
1)年等于 2014
。它是否正确?
2)如果您想获取单个日期的数据,请使用:
2 things:
1) year is equal 2014
. Is it correct?
2) If you want to fetch data for single date, use:
WHERE EntryDate = '01/08/2014'
有时,您需要使用设置日期格式 [ ^ ]命令以正确获取数据。
Sometimes, you need to change date format using SET DATEFORMAT[^] command to properly fetch data.
SET DATEFORMAT mdy; --for other parameters, see the documentation
SELECT ...
FROM ...
WHERE datefield = '01/08/2013'
尝试更改此内容:
try changing this:
BETWEEN '2014/01/01' AND '2014/01/07'
这应该有效
This should work
BETWEEN '01 Jan 2014' AND '07 Jan 2014'
这篇关于在sql server 2008中选择问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文