ALTER PROCEDURE [dbo].[SP_My_Procedured]
AS
BEGIN
SELECT Mission_Time
FROM Mission_Table
WITH (NOLOCK)
WHERE
cast(getdate() as Date)=Mission_Time
END
当我运行SP_My_Procedured时,
我认为Mission_Time 为
"2014-01-04 08:35:05.510"
"2014-01-03 10:49:00.697"
但是我希望看到如下,
"2014-01-04"
"2014-01-03"
那么如何通过select?
在存储过程中执行此操作任何帮助将不胜感激。
答案 0 :(得分:0)
将SELECT
列表中的值转换为Date
:
ALTER PROCEDURE [dbo].[SP_My_Procedured]
AS
BEGIN
SELECT
Mission_Time = cast(Mission_Time as Date)
FROM
Mission_Table (NOLOCK)
WHERE
cast(Mission_Time as Date) = cast(getdate() as Date)
END
[顺便说一句:使用NO LOCK
存在危险]
[此外,如果列已经是Date类型(您没有指定其类型),则可能不需要将列转换为日期。这样做可能会导致没有使用适当的索引]
答案 1 :(得分:0)