andrey.esaulov Posted July 14, 2020 Share Posted July 14, 2020 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 QuerySELECT 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) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now