dimpythewimpy (9/19/2016)
Can someone suggest a workaround for this. I have researched online and tried inline function but,that didn't work as I am not returning a table here. It is just a single variable.
Read the following article. It's not just about how to make scalar functions run faster. It's also about how to use an iTVF to return a Scalar Value. You'll have to change the way you use it compared to a true Scalar Function but paradigm shift is easy and makes for very fast code.
http://www.sqlservercentral.com/articles/T-SQL/91724/
--Jeff Moden
Change is inevitable... Change for the better is not.