GETDATE() in SQL Server

Transact-SQL statements can refer to GETDATE anywhere they can refer to a datetime expression.

GETDATE is a nondeterministic function. Views and expressions that reference this function in a column cannot be indexed.

Using SWITCHOFFSET with the function GETDATE() can cause the query to run slowly because the query optimizer is unable to obtain accurate cardinality estimates for the GETDATE value. We recommend that you precompute the GETDATE value and then specify that value in the query as shown in the following example. In addition, use the OPTION (RECOMPILE) query hint to force the query optimizer to recompile a query plan the next time the same query is executed. The optimizer will then have accurate cardinality estimates for GETDATE() and will produce a more efficient query plan.

SELECT RIGHT(YEAR(Creation_Date), 2) YY FROM Table_Name

Result

| YY |
------
| 10 |
| 11 |
| 13 |
about author

Suraj Kumar

surajkumarkhg8844@gmail.com

I am a Freelance Software Developer and Website Designer

Leave a Reply

Your email address will not be published. Required fields are marked *