Performance and profiling on SELECT * FROM [table] ISNULL([column], '') = '' VS EXIST (SELECT * FROM [table] WHERE [condition]) I asked a similar question here. The answerer told me to ask about profiling and performance here on [dba.stackexchange].

I have two condition in my queries that both do the same thing. I was wondering how can I mesure the performance of both to choose the best one. I know I should do profiling, but i don't know how. I've read this and found it to be more confusing than helping. And do do not wish to profile the whole query, only this condition.

IF (SELECT * FROM [table] WHERE ISNULL([column], '')) = ''

IF EXIST (SELECT [column] FROM [table])

I expect the second way to be more performant because it does not call a function, but i am far from being an expert in SQL.

How can i profile them?

or which one is the best?
Well, the IF (SELECT * FROM [table] WHERE ISNULL([column], '')) = '' test isn't really a working test, so it is possible that you made whatever code you are working with too generic when posting here. HOWEVER, in a very general sense, the IF EXISTS should nearly always be better because it is designed to stop processing its inner query upon the first row being returned to it. The first condition you posted does not have that built-in efficiency and would process all rows in the inner query. Of course, sometimes the Query Optimizer can re-write your code to be an IF EXISTS if it recognizes that your non-IF EXISTS query would logically be the same, but I am not sure if that would happen in this specific case. I believe I have seen that the Query Optimizer does rewrite IF ( (SELECT COUNT(*) FROM [table]) &gt; 0 ) as an IF EXISTS.

Regarding how to test the efficiency of each, I would use a base query against the same table so that I could use the same column(s) for filtering (to hopefully make use of the same indexes that the real queries would use) and repeat that query, once for each of the two conditions you are testing for. Then, wrap each in SET STATISTICS TIME, IO [ON | OFF]; as follows:

SET STATISTICS IO, TIME ON;
IF (SELECT * FROM dbo.Table WHERE ISNULL()... )
BEGIN
  PRINT 'First';
END;
SET STATISTICS IO, TIME OFF;

PRINT '-----------';

SET STATISTICS IO, TIME ON;
IF (EXISTS(SELECT * FROM dbo.Table WHERE condition))
BEGIN
  PRINT 'Second';
END;
SET STATISTICS IO, TIME OFF;


Please read the MSDN page for the EXISTS operator for more info regarding how to use it in WHERE conditions.