title: Using IF..ELSE with multi INSERT INTO using Subquery
body: <p>I have two table on database related to each other through foreign key
  table1 is journal
  table2 is journalEntries
  I have a query to check if there is row on current date from table journal if there is a record then it will insert record to journalEntries
  if it is null then it will insert record on journal table1 then insert to journalEntries table2</p>
  
  <p>I tried different way but it doesn't work</p>
  
  <pre><code>if (select j_id from journal where [date] &gt; (SELECT CONVERT(VARCHAR(10),GETDATE(),111))) is null
  insert into journal values (getdate() as [date], getdate() as [insert_date], '' as notes)
  insert into journalentries (j_id, acc_num, credit, debit, [user_id], note)
  select (select (select j_id from Journal where [date] in (SELECT CONVERT(VARCHAR(10),GETDATE(),111))) as j_id, @acc_num, @credit, @debit, @user_id, @note)
  
  else
  insert into journalentries (j_id, acc_num, credit, debit, [user_id], note)
  select (select j_id from Journal where [date] in (SELECT CONVERT(VARCHAR(10),GETDATE(),111))) as j_id, @acc_num, @credit, @debit, @user_id, @note
  end
  </code></pre>
  
  <p>another way</p>
  
  <pre><code>if(select j_id from journal where [date] in ('2019-01-01')) is null
  insert journal([date], insert_date, notes)
  OUTPUT inserted.j_id, '2019-01-01', '2019-01-01', ''
  INTO dbo.journalentries(j_id, acc_num, credit, debit, [user_id], note)
  values (j_id, @acc_num, @credit, @debit, @user_id, @note)
  else
  select (select j_id from Journal where [date] in (SELECT CONVERT(VARCHAR(10),GETDATE(),111))) as j_id, @acc_num, @credit, @debit, @user_id, @note
  </code></pre>