Sorry for any incorrect terms as I am not proficient in SQL…
I have a query that I need to run daily, however the table that I need to query includes todays date. Normally I run:
SELECT m.displayName, a.source, count(a.agentGuid)
FROM ntEventLog20120725 AS a
LEFT OUTER JOIN machNameTab AS m ON a.agentGuid = m.agentGuid
WHERE a.eventTime > DATEADD(hour, -1, CURRENT_TIMESTAMP)
GROUP BY a.agentGuid, m.displayName, a.source
HAVING COUNT(a.agentGuid) > 1000
ORDER BY m.displayName
However the table I want to query each day is different. Todays table is ntEventLog20120725, tomorrows will be ntEventLog20120726. I know how to get the date in that format:
SELECT CONVERT(varchar, getDate(), 112)
I just do not know how to combine the two together so that I can schedule this to run everyday.
you can do this using dynamic query. though using dynamic query is not a good practice. But I guess that is the only option here
As triclosan mentioned in the comment, you should consider redesigning the table. Not a good practice to have tables for each day