title: How Can I Do This ORACLE Statement in SQL Server?
body: <pre><code>SELECT COUNT(Field1_) 
             FROM 
             (
                 SELECT Field1_
                 FROM Table1_
                 WHERE Field1_= @Field1
             UNION ALL
                 SELECT Field1_
                 FROM Table2_
                 WHERE DeliveryPoint_ = @Field1
             UNION ALL
                 SELECT Table3_
                 FROM GasSupplied_
                 WHERE DeliveryPoint_ = @Field1
             UNION ALL
                 SELECT Table4_
                 FROM Gnsnominations_
                 WHERE DeliveryPoint_ = @Field1
             UNION ALL
                 SELECT Table5_
                 FROM HourlyProfileReports_
                 WHERE DeliveryPoint_ = @Field1
             )
  </code></pre>
  
  <p>And I have problems with this code. Please help me.</p>
  
  <pre><code>DECLARE
                CountedRows NUMBER;
              BEGIN
                SELECT COUNT(*) INTO CountedRows 
                FROM Profiles_ 
                WHERE Field1_ = @Param1 AND RowNum &lt; 2;  
                  IF(CountedRows &gt; 0)
                  THEN
                      UPDATE Profiles_ 
                      SET 
                          Field2_ = @Param2,
                          Field3_ = @Param3,
              Field4_ = @Param4 
                          WHERE Field1_ = @Param1;
                  ELSE
                  INSERT INTO Profiles_
                  (
                      Field1_, 
                      Field2_,
                      Field3_,
                      Field4_
                  ) 
                  VALUES
                  (
                      @Param1, 
                      @Param2,
                      @Param3,
                      @Param4                    );
                  END IF;
                END;
  </code></pre>
  
  <p>Please help me. I read many books and tutorials but I can't understand this.</p>