I have a curious question about efficiency. Say I have a field on a database that is just a numeric digit that represents something else. Like, a value of 1 means the term is 30 days.
Would it be better (more efficient) to code a SELECT statement like this…
SELECT CASE TermId WHEN 1 THEN '30 days' WHEN 2 THEN '60 days' END AS Term FROM MyTable
…and bind the results directly to the GridView, or would it be better to evaluate the TermId field in RowDataBound event of the GridView and change the cell text accordingly?
Don’t worry about extensibility or anything like that, I am only concerned about the differences in overall efficiency. For what it’s worth, the database resides on the web server.
Efficiency probably wouldn’t matter here – code maintainability does though. Ask yourself – will these values change? What if they do? What would I need to do after 2 years of use if these values change? If it becomes evident that scripting them in SQL would mean better maintainability (easier to change), then do it in a stored Procedure. If it’s easier to change them in code later, then do that. The benefits from doing either are quite low, as the code doesn’t look complex at all.