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 7912389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:35:15+00:00 2026-06-03T13:35:15+00:00

I have dwelling on this for hours and still cannot find out how to

  • 0

I have dwelling on this for hours and still cannot find out how to do this. How do you get the total sales of an item for every year.

What I have got so far is this:

SQLCommand.CommandText = @"SELECT SUM SalesNo AS TotalYearSales FROM SalesTable WHERE Product = " + ddItems.SelectedItem + "";.

The table headings are as follows Product, Year, SalesNo.

  • 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-03T13:35:16+00:00Added an answer on June 3, 2026 at 1:35 pm
    SQLCommand.CommandText = @"SELECT DatePart( YY, SalesDate ), SUM( SalesNo ) AS TotalYearSales FROM SalesTable WHERE Product = ? GROUP BY DatePart( YY, SalesDate ) ";
    SQLCommand.Parameters.Add( "parmForProduct", ddItems.SelectedItem );
    

    As Daniel pointed out, you would be wide open to sql-injection attacks and should parameterized queries.

    To get total by year, you have to add the year as a basis of the query too. I don’t know the “date” column in your table the transactions are based on, so you’ll have to adjust. The “?” in the query is a “place-holder” for the parameter added immediately after.. And parameters should be added in the same order as listed in the query. Some SQL engines allow “named” parameters and use something like “@ProductIWant”, and your parameter would use the same…

    Since you are querying for only a specific product, that doesn’t need to be in the list.. unless you wanted ALL products grouped by year.

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

Sidebar

Related Questions

Have a look at this url: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:jquery_ui_methods#column_chooser I have got the Column Chooser dialog
have Googled the cr*p out of this one so apologies if the answer is
Have you any idea how to find out if spell check suggestions dialog is
Have you managed to get Aptana Studio debugging to work? I tried following this,
I've been dwelling on this for a while. I have this string (there are
How can I modify this: /services/type/single_dwelling/ to this: /ajax/services/single_dwelling/development Currently I have: linkUrl =
Have a look at this picture alt text http://www.abbeylegal.com/downloads/2009-04-01/web%20part%20top%20line.jpg Does anyone know what css
Have someone tried out DeCAL in Delphi 2009? I'm thinking about upgrading from 2007,
Have a matrix report now that has Position, Hours and Wages for a location
Have converted devise new session from erb to Haml but doens't work, this is

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.