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

  • SEARCH
  • Home
  • 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 9130591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:59:24+00:00 2026-06-17T07:59:24+00:00

I am trying to run a SQL query that will update information in a

  • 0

I am trying to run a SQL query that will update information in a specific table. the problem I am running into is that I need the query to pull today’s date, for whatever the date may be when the query is run, and then only pull records going back to years. I then want it to return an AVG of the CUR_CASH_UNITS over that two year time period. I have tried DATEDIFF and DATEADD and those do not appear to work with the system I have because it returns a *libl error. Here is what I have:

Select  Month,
    SSSALESNAM,
    CAT,
    Sum(Units) as Units     
From    DW****.******EG
Inner Join  (Select CAT,
                STORE,
                MONTH(DATE) As Month,
                Sum(CUR_CASH_UNITS) As Units
         From   DW*******.****AT        
         Inner Join (Select CAT,
                            CATNUM
                     From   DW****.*****ST) As Category_List             
        On         DW*******.****AT.CATEGORY_NUMBER=Category_List.CATNUM
        --Where  (((CUR_CASH_UNITS.MONTH(DATE)) Between MONTH(DATE) And (MONTH(DATE)-24MONTH))
        Group by Cat,
                 Store,
                 MONTH(DATE)) As Cash_Units

On          DW****.******EG.SSSTR=Cash_Units.STORE           
Group By    Month,
        SSSALESNAM,
        CAT
Order By    Month,
        SSSALESNAM

The section above that is commented out is just one of my attempts to get the date arithmetic to work. With the Where statement commented out the query executed correctly. The date column in my table is labeled as DATE with a format of YYYY-MM-DD. Kind of new to SQL so I apologize in advance if it is something simple that I am overlooking.

  • 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-17T07:59:25+00:00Added an answer on June 17, 2026 at 7:59 am

    I think you want a where clause like the following:

    where "date" between current date - 2 years and current date
    

    You need the double quotes because date is a reserved word. The rest is just for getting a date in the past two years.

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

Sidebar

Related Questions

I'm trying to run code that will copy fields into a new table, moving
I am trying to run a SQL Query in phpmyadmin that will total multiple
I am trying to run a SQL query (SQL Server) that will look up
I am trying to build a sql query which will run a stored procedure.
I'm trying to create a query that will update the value of rgn_no and
I am trying to run a query that for a selected person, it will
I am trying to fabricate an SQL query that will provide these results: |
I am trying to write an SQL query that will sort based on a
I am trying to make a simple query that will update a user database
Hi I am trying to run this query in SQL but it is not

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.