title: SQL Check constraint on column referencing other columns
body: <p>I want to limit a column that it can only have a value when another column has a value.</p>
  
  <p>example: (this doesn't work)</p>
  
  <pre><code>create table testConstraint (
  col1 int not null identity(1, 1) primary key,
  col2 int,
  col3 int check (col2 is not null),
  col4 int)
  </code></pre>
  
  <p>This is not possible because he cannot reference another column.
  Error:</p>
  
  <blockquote>
    <p>Column CHECK constraint for column 'col3' references another column,
    table 'testConstraint'.</p>
  </blockquote>
  
  <p>Another try was: (also doesn't work)</p>
  
  <pre><code>create table testConstraint (
  col1 int not null identity(1, 1) primary key,
  col2 int,
  col3 int,
  col4 int)
  GO
  
  alter table testConstraint add constraint ck_columnNotNull check (case when col2 is null then col3 is null end)
  GO
  </code></pre>
  
  <p>Anyone have an idea how this would be possible with a constraint?</p>