title: Select Max Number From Multiple Tables
body: <p>I am working on a Code Receipt Number Auto Generate. Here is my code:</p>
  
  <pre><code>var conrecipt = new SqlConnection(
      ConfigurationManager.ConnectionStrings["con"].ConnectionString);
  conrecipt.Open();
  var cmd = new SqlCommand("Select COALESCE(MAX(Reciptno),0) from Registration", conrecipt);
  int i = Convert.ToInt32(cmd.ExecuteScalar());
  conrecipt.Close();
  i++;
  Label3.Text = Reciptno + i.ToString();
  </code></pre>
  
  <p>It's working fine. But I need to check 3 tables : Registration, Advance and one more table and need to find max from those id's. </p>
  
  <p>How can I do this in Asp.Net C# and MS SQL Server 2012?</p>