7 Replies Latest reply on Jun 21, 2012 2:41 PM by Robert Morton

    Custom SQL - Multiple Queries

    Nat Lutz

      Is there some way that the Custom SQL area can be used to run a string of queries - just selecting the information created in the last step?


      Background on what I'm doing - I need to first aggregate certain data based on dates. These aggregated dates (minimum and maximum) are placed into a temp table with unique record identifiers.


      The second step is then to use these aggregated dates to join to another table by data and unique identifiers to pull what is needed. (The idea is to compare first and last and see the changes).


      Is there anyway to make this structure work within the queries? Right now I have to run the queries manually in SQL Server before importing which makes setting up automatic refreshes impossible. Also as an FYI, putting this into one query will not work. This is a very simplified version of what I'm doing and the single query will not work / is extremely slow. (In fact my string of queries in one case is actually 4 temp tables and 1 final output)


      SELECT Max(date) AS maxdate, uniqueidentifier

      INTO #tmp

      FROM table1


      SELECT *

      FROM #tmp JOIN table2 ON uniqueidentifier = uniqueidentifier and date = maxdate