Domanda

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())
È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top