title: Check if exactly one variable is not null
body: <p>In a trigger in my sql-server 2008 database I need to check if exactly one variable is not null. This code does what I need, but can it be done in fewer lines and more readable?</p>
  
  <pre><code>DECLARE @string varchar
  DECLARE @float float
  DECLARE @bit bit
  DECLARE @int int
  
  Set @string=NULL  -- Exactly one of these variables needs to be set
  Set @float=NULL   --
  Set @bit=NULL     -- 
  Set @int=NULL     --
  
  IF(   (@string is not null AND COALESCE(@float, @bit, @int) IS NULL)
      OR (@float is not null AND COALESCE(@string, @bit, @int) IS NULL)
      OR (@bit is not null AND COALESCE(@string, @float, @int) IS NULL)
      OR (@int is not null AND COALESCE(@string, @float, @bit) IS NULL)
  )
  print ' ok'
  ELSE 
  print ' not ok'
  </code></pre>