我想问一下如何从SQL Server DateTime
查询中的Select
列获取MIN DatePart。
这是我的疑问:
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
请帮忙......
答案 0 :(得分: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]
答案 1 :(得分:0)
使用下面的聚合查询
select min(date) from tablename