Question

What happens if use SYSUTCDATETIME() in a view? Will the view work correctly? When will it execute the SYSUTCDATETIME function?

For instance I ve created a view from the following select

SELECT * FROM dbo.contracts
WHERE (contract_start < SYSUTCDATETIME()) AND (contract_end > SYSUTCDATETIME())
Was it helpful?

Solution

It (SYSUTCDATETIME()) will return the value (as any other function) at the time of execution of the view.

Execute this query several time and see for yourself

SELECT *, SYSUTCDATETIME() sysutcdatetime FROM contracts
WHERE (contract_start < SYSUTCDATETIME()) AND (contract_end > SYSUTCDATETIME());

SQLFiddle

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top