Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8294047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:03:54+00:00 2026-06-08T14:03:54+00:00

Sorry for any incorrect terms as I am not proficient in SQL… I have

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T14:03:56+00:00Added an answer on June 8, 2026 at 2:03 pm

    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

    declare @date_val char(8)
    select @date_val=convert(varchar,getDate(),112)
    
    exec('
    SELECT m.displayName,a.source,count(a.agentGuid) from ntEventLog'+@date_val+' a LEFT OUTER JOIN machNameTab 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')
    

    As triclosan mentioned in the comment, you should consider redesigning the table. Not a good practice to have tables for each day

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry I cannot post any source code... I have a code running a master/slave
sorry in advance for any orthographic mistakes (english is not my first language). I
Sorry about the extremely vague question title (any suggestions for improvements welcome) I have
Sorry if this is too remedial or repetitive in any way but I need
Sorry if this is a dup; I haven't found any questions that pose quite
I have a LINQ Query that creates a new type that contains a days
I'm a Pyro and CI noob, so sorry for any obvious omissions. I'm building
Sorry for this silly question, but is there any way to restrict using directives
UPDATE Turns out I'm just tired. There isn't any problem here sorry for wasting
sorry for any inconveniece caused. Would like to ask about database or rather databinding

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.