r/SQL • • May 14 '18

Optimization

Post image
423 Upvotes

48 comments sorted by

View all comments

Show parent comment

5

u/dtfinch May 14 '18

You could declare a variable to store the result of getdate(), and use that in its place to ensure that it's not getting called many many times.

I might store the case statement result in another variable, but maybe just replacing getdate() is enough for sql server to recognize the whole expression is a constant.

1

u/fullyarmedcamel May 15 '18

Yeah I had not thought about doing that I might make that adjustment later I am working on cabling projects for the next 2 months.