GETDATE score twice in the statement - will it always be the same?

Suppose

isnull(some_column, getdate()) >= getdate()

where is the logic, if some_column is null, this expression should always be true. However, this will always be so (since some time has passed between the two getdate () evaluations and they will not be equal)?

+5
source share
5 answers

, . , GETDATE() - , , . , , .

, :

declare @cnt int = 0, @i int = 0
while @cnt = 0 
begin
    select @cnt = count(*)
    from master..spt_values 
    where getdate() != getdate();
    set @i += 1;
    if @cnt != 0
        raiserror(N'@cnt = %d this shoudl not happen but it dit after @i = %d', 16, 1, @cnt, @i);
end

:

Msg 50000, Level 16, State 1, Line 9
@cnt = 2515 this shoudl not happen but it dit after @i = 694

, ( ), : ():

GETDATE()

+4

, getDate() . ...

:

isnull(some_column, '2999-01-01') >= getDate()

declare @some_column(datetime)
select case when isnull(@some_column,'2999-01-01') >= getdate() then 1 else 0 end

1.

:

(some_column >= getdate() or some_column is null)
+3

GETDATE(), , .

:

DECLARE currentDate DATETIME

SELECT currentDate = GETDATE()

isnull(some_column, currentDate) >= currentDate 
+2

SQL Server 2000 getdate() , ONCE SQL-. 2005 , getdate , , .

+1

Why do you want to use the date. I mean, there is no reason to ask the sql server to evaluate / process the true default condition. You can use instead

isnull(some_column, 2) >= 1
0
source

All Articles