0

我想问一下如何从SQL Server查询中的DateTime列中获取 MIN DatePart。Select

这是我的查询:

SELECT  
   MIN(CAST(DATEPART(DD, DateCreated) AS NVARCHAR) + 
   N'/' +
   CAST(DATEPART(MM, DateCreated) AS NVARCHAR) + 
   N'/' +
   CAST(DATEPART(YYYY, DateCreated) AS NVARCHAR)) AS DateFrom
FROM    
   [User]

结果应该是04/04.2013,但现在,结果是01/04/2014

请帮忙 ....

4

2 回答 2

1
SELECT  MIN(CAST(DATEPART(DD,DateCreated) AS NVARCHAR) + 
        N'/' +
        CAST(DATEPART(MM,DateCreated) AS NVARCHAR) + 
        N'.' +
        CAST(DATEPART(YYYY,DateCreated) AS NVARCHAR)) AS DateFrom
FROM    [User]
于 2014-09-02T11:57:37.720 回答
0

使用如下聚合查询

select min(date) from tablename
于 2014-09-02T11:59:31.273 回答