I need some help in figuring out how to join tables to my query. The table names change every day as the date is used in the table name and older tables are dropped as they are no longer needed.
My query looks for “scans” that have data in the database and are in the process of being processed (for a lack of a better word).
My current query is:
USE RetinaCSDatabase SELECT S.ScanID [Scan ID], S.PolicyName [Scan], DATEADD(hh, +2, S.StartTime) [Scan Start], A.AssetName [Scanner], COUNT(AIPS.AssetIPID) [Hosts], S.TransactionGroup [Transaction Group ID] FROM Scan S (NOLOCK) LEFT JOIN Scanner SC (NOLOCK) ON S.ScannerID = SC.ScannerID LEFT JOIN Asset A (NOLOCK) ON SC.AssetID = A.AssetID LEFT JOIN Asset_IP_Scan AIPS (NOLOCK) ON S.ScanID = AIPS.ScanID WHERE S.ProcessStatus < 2 GROUP BY S.ScanID, S.PolicyName, S.StartTime, A.AssetName, S.TransactionGroup ORDER BY S.StartTime ASC, S.PolicyName ASC, A.AssetName ASC
What I need to join is the table(s) with the data still requiring processing. Those tables start with the name “evt_scan_” and then the date. So, a full table name would be “evt_scan_20171222” for example. The data for a scan performed on the 22nd of December 2017 will have data in the table “evt_scan_20171222” and possibly in the following days table, “evt_scan_20171223”. So, I need my query first to check if the table exists and then join it to do a count and also to check if the following days table exists, join it to do another count and add up the 2 counts to show the outstanding records requiring processing.
If the table names were static I would join them with this query:
LEFT JOIN evt_scan_20171222 evt1 ON S.TransactionGroup = evt1.evtTransactionGroup
It would also require a WHERE statement returning only records where evtStatus = 0.
✓ Extra quality
ExtraProxies brings the best proxy quality for you with our private and reliable proxies
✓ Extra anonymity
Top level of anonymity and 100% safe proxies – this is what you get with every proxy package
✓ Extra speed
1,ooo mb/s proxy servers speed – we are way better than others – just enjoy our proxies!
USA proxy location
We offer premium quality USA private proxies – the most essential proxies you can ever want from USA
Our proxies have TOP level of anonymity + Elite quality, so you are always safe and secure with your proxies
Use your proxies as much as you want – we have no limits for data transfer and bandwidth, unlimited usage!
Superb fast proxy servers with 1,000 mb/s speed – sit back and enjoy your lightning fast private proxies!
99,9% servers uptime
Alive and working proxies all the time – we are taking care of our servers so you can use them without any problems
No usage restrictions
You have freedom to use your proxies with every software, browser or website you want without restrictions
Perfect for SEO
We are 100% friendly with all SEO tasks as well as internet marketing – feel the power with our proxies
Buy more proxies and get better price – we offer various proxy packages with great deals and discounts
We are working 24/7 to bring the best proxy experience for you – we are glad to help and assist you!