title: How to check if a select query result is NULL in SQL Server
body: <p>in SQL Server , how do I verify if a query has returned NULL and run blocks depending on it . e.g. in query 1 , I want to check <code>if count(*) is not null</code> and then check if it has >0 . Should I use <code>if exists</code> here ?</p>
  
  <pre><code>if select count(*) from tbl1 not is NULL then 
     if select count(*) from tbl1 where count(*)&gt;0 then
        raiserror()
     end if 
  end if 
  </code></pre>
  
  <hr>
  
  <p>In Oracle one can say <code>IF INSERTING THEN</code> or <code>IF updating THEN</code> or <code>if deleting then</code> run a certain block of code based on a column  . how do we do it in SQL Server ? Please see Oracle code below .</p>
  
  <pre><code>CREATE OR REPLACE TRIGGER tr_name
      BEFORE DELETE OR INSERT OR UPDATE OF column1 ON tbl1
      FOR EACH ROW
      WHEN (NEW.column1 IS NOT NULL)
  begin
  IF INSERTING THEN
      run some code like check if there are more than row in a table and if &gt;0 then not allow any    inserts 
  IF updating THEN
      run some code 
  IF deleting THEN
      run some code 
  end
  </code></pre>