title: UNION on parameters SQL
body: <p>I have three parameters in my stored procedure. On two of them I execute a SELECT statement to retrieve a specific value. I want to use the third parameter to make a UNION on the first two parameters.
  Basically this is how it looks kinda.</p>
  
  <pre><code>DECLARE @MaxDate1
  DECLARE @MaxDate2
  DECLARE @AllDate
  SELECT @MaxDate1 = MAX(Date) FROM Table1
  SELECT @MaxDate2 = MAX(Date) FROM Table2
  </code></pre>
  
  <p>This is what I would like however I can't figure out how to write the query in this case.</p>
  
  <pre><code>SET @AllDate = @MaxDate1 UNION @MaxDate2
  </code></pre>
  
  <p>Thank you for the help, or suggestions.</p>
  
  <p>Well since I received lots of minuses I will try to explain how I tried to do the whole thing. I have a stored procedure where first I look up the latest dates from two different tables. After I look up the dates I create an IF ELSE statement stating that if the date selected by the user is bigger than the one in the database then it should return an error, however if the date is smaller than the MaxDate then all columns and rows should be returned up to the selected date. However the dates are dynamic so the query looks them up each time. Therefore it takes long to check the MaxDate and according to that to look up the fields also...the connection times out. So I was trying to make a union on the MaxDate of the two fields, and use the @AllDate as parameter to be checked to the selected date. Hope its a bit more clear :) </p>