开发者

How do I select the min from a function in SQL?

I want to take the difference between my date column and the current date, find the minimum and store it in a variable.

I have:

DECLA开发者_如何学编程RE @DAY AS INTEGER;
SET @DAY = 
    SELECT MIN (
        SELECT DATEDIFF(DAY, date_col, GETDATE())
        FROM tb1);

but the min function isn't accepting the select and the datediff function.


Try the following:

SELECT MIN (DATEDIFF(DAY, date_col, GETDATE()))
FROM tb1

You don't need the nested select.


select @day = min(DateDiff(DAY,date_col,GetDate())) from tbl
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜