这是我的程序,我无法获取特定日期的记录..
我有特定日期的数据,但输出为零.. 但是当我使用> =它给我数据..
使用= @Date作为参数给出零输出..
使用> = @Date作为参数提供输出
我的程序在哪里需要修改以根据提供的日期获取数据。
Declare @ids varchar(max);
set @ids = (select ids from USers where UserId = 10)
select F.Date as DateOfuser,F.ID , (B.FirstName + ',' + B.LastName) as Name,
A.Group ,E.companyname,E.company ,D.receivedDate
from Details as A
inner join Usersnew as B
on A.newId = B.newId
inner join Files as D
on D.DocId = B.Docid
Inner join PDetails as C
on (D.GId = c.GId and D.PId = C.Id and D.IsActive='True' and
(convert(datetime,D.ReceivedDate, 20) = @Date )) -- @parameter @date // no output
and D.GId in(select ID from fnSplitter(@ids))
inner join PDetails as E
on E.PId = C.Id
inner join Information as F
on F.PId = E.PId
如何获取作为参数传递的特定日期的记录..
我有数据,但它没有返回我如何修改我的程序来获取 数据
我需要根据日期得到输出。我有通过日期收到的数据,所以日期作为参数传递..
请帮帮忙?
任何想要获取作为参数传递的特定日期的记录吗?
为什么
你可以解释一下吗?=未返回> =正在返回
我们在等于传递日期的过程中传递=操作数?
答案 0 :(得分:1)
@Simon说。比较日期和日期时间可能存在问题。比较日期和日期时间时,日期会转换为日期时间,例如“2017-07-04”投放至“2017-07-04 00:00:00.000”。 更改行:
on (D.GId = c.GId and D.PId = C.Id and D.IsActive='True' and
(convert(datetime,D.ReceivedDate, 20) = @Date ))
为:
on (D.GId = c.GId and D.PId = C.Id and D.IsActive='True' and
(convert(datetime,D.ReceivedDate, 20) >= @Date) AND (convert(datetime,D.ReceivedDate, 20) < DATEADD(dd,1,@Date)))
您也可以将其更改为:
on (D.GId = c.GId and D.PId = C.Id and D.IsActive='True' and
(cast(D.ReceivedDate as date) = @Date ))