Jump to content
We've recently updated our Privacy Statement, available here ×

Getting data from a dynamic sequence of SQL tables


andrey.esaulov

Recommended Posts

I want to get data from a dynamic sequence of MS SQL tables (archive) of the form TiSe1 - TiSeN.
I can get the names of all TiSe tables through SQL from a common table. The number of tables increases over time, more recent measurement archives are written to new tables.
How can I connect a sequence of tables in a query?

I am thinking of repeating UNION SELECT, but I need to get the entire list of tables in the query first and substitute it into the queryString.

This is my current Query

SELECT
    MIN(NULLIF(Value,0)) AS VAL_START,
    MAX(Value) AS VAL_END,
    MAX(NULLIF(Value,0)) - MIN(NULLIF(Value,0)) AS VAL_DIFF,
    datepart(DD,SourceTime) AS DAYS,
    datepart(HH,SourceTime)+1 AS HOURS
    FROM dbo.TiSe3
    WHERE SourceTime BETWEEN $P{DateFrom} AND $P{DateTo}
    AND HDB_DpIdTs = $P{ID}
    Group by datepart(HH,SourceTime), datepart(DD,SourceTime)
    ORDER BY datepart(DD,SourceTime), datepart(HH,SourceTime)

 

hdb.png

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...