I’ve heard that in some programming languages it is faster to check if the length of a string is 0, than to check if the content is "". Is this also true for T-SQL?
Sample:
SELECT user_id FROM users WHERE LEN(user_email) = 0
vs.
SELECT user_id FROM users WHERE user_email = ''
Edit
You’ve updated your question since I first looked at it. In that example I would say that you should definitely always use
Not
The first one will allow an index to be used. As a performance optimisation this will trump some string micro optimisation every time! To see this
Execution Plans
Original Answer
In the code below (SQL Server 2008 – I “borrowed” the timing framework from @8kb’s answer here) I got a slight edge for testing the length rather than the contents below when
@stringToTestcontained a string. They were equal timings when NULL. I probably didn’t test enough to draw any firm conclusions though.In a typical execution plan I would imagine the difference would be negligible and if you’re doing that much string comparison in TSQL that it will be likely to make any significant difference you should probably be using a different language for it.