出现"Lessthan或等于"的问题. [英] Problem with "Lessthan or Equal to"

查看:100
本文介绍了出现"Lessthan或等于"的问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

在查询中使用小于或相等条件时,我遇到问题.

Hi All,

I am facing a problem when used lessthan or equal codition in a query.

 StartDate <= CONVERT(datetime, @pi_Date, 101)

@pi_Date = EnteredDate.

当我在sql查询的where子句中使用以上条件时,我只会得到小于EnteredDate的记录.

如何获取StartDate小于或等于EnteredDate的记录.

请帮帮我...

-
谢谢,
Gopi.

when I am using the above condition in where clause of a sql query, I am getting only the records which are lessthan the EnteredDate.

How to get the records for which StartDate is less than or equal to the EnteredDate.

Please help me...

--
Thanks,
Gopi.

推荐答案

如果您的@PI_Date仅存在一个月,一年和一年,现在是时间标记,则时间指示设置为0:00:00.000.

您可以在@pi_Date varchar中添加"23:59:59.999",而问题就消失了.
另一种选择是将1天添加到@PI_Date
if your @PI_Date exists only of a day a month and a year and now time indiciaton, the time indication is set to 0:00:00.000.

you can add '' 23:59:59.999'' to the @pi_Date varchar and your problem is gone.
Another option is to add 1 day to @PI_Date


嘿,

我得到了答案....

在SQL Server 2008及更高版本中,有一个名为DATE的数据类型,它仅给出日期而没有时间...这解决了我的问题


祝您编程愉快,
Gopi.
Hey,

I got the answer for it....

In SQL server 2008 and above, there is a datatype named DATE which gives only date without time... this solved my problem


Happy coding,
Gopi.


要解决此问题而不更改数据类型(即使用DateTime数据类型),只需执行
1.加1天
2.减去1秒.

To solve the issue without changing the datatype (i.e., using the DateTime datatype), just do this
1. Add 1 day
2. Subtract 1 second.

set @date = dateadd(s, -1, dateadd(d, 1, @date))


这篇关于出现"Lessthan或等于"的问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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