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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:34:23+00:00 2026-06-05T07:34:23+00:00

I am very new to SQL, well rather, I have not used it in

  • 0

I am very new to SQL, well rather, I have not used it in 8 years or so. This is being done in a restaurant point-of-sale system that uses SQL Server. Anyhow, here is my current code:

select cashier_id,grand_total, num_people_party, datetime
from invoice_totals
where datetime >= '2012-06-01'

Ultimately I want to display a report that lists the total number of people served (num_people_served) and the grand total (grand_total) by the cashier id (cashier_id) for each date.

So:

Cashier ID 223
2012-06-01   10   200.00
2012-06-02   23   245.00

Cashier ID 224
2012-06-01   15   123.00
2012-06-02   24   254.00

etc...

This should not be too tough, but I just don’t remember and my searches have not proven useful. Also, it should be noted that the DateTime field will need to be split in order to group the totals by date.


In adding the dividion field from the comment below, I get the following error once it is added:

Message: Could not retrieve datatable.
SELECT CASHIER_ID AS SERVER, CONVERT(VARCHAR(10),[DATETIME],111) AS DATE, SUM(GRAND_TOTAL) AS TOTAL_SALES, SUM(NUM_PEOPLE_PARTY) AS NUMBER_SERVED, SUM(GRAND_TOTAL) / SUM(NUM_PEOPLE_PARTY) AS CASHPERCUSTOMER
FROM INVOICE_TOTALS
WHERE [DATETIME] >= '2012-06-01'
GROUP BY CASHIER_ID, CONVERT(VARCHAR(10),[DATETIME],111) 
Stack Trace:    at PCA_DataMod.PCA_DB.OpenDT(String SQLLoadInfo, Boolean NoSchema)
   at PCA_DataMod.PCA_DB.OpenDT(String SQLLoadInfo)
   at pcAmerica.Desktop.POS.Forms.frmReportCustomWiz.GetRawSQLFields()
   at pcAmerica.Desktop.POS.Forms.frmReportCustomWiz.Display_Step(WizardStep Index)

Message: Divide by zero error encountered.
Stack Trace:    at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlDataReader.HasMoreRows()
   at System.Data.SqlClient.SqlDataReader.ReadInternal(Boolean setTimeout)
   at System.Data.SqlClient.SqlDataReader.Read()
   at System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping mapping)
   at System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue)
   at System.Data.Common.DataAdapter.Fill(DataSet dataSet, String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
   at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
   at PCA_DataMod.PCA_DB.OpenDT(String SQLLoadInfo, Boolean NoSchema)

Any ideas?

  • 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-05T07:34:24+00:00Added an answer on June 5, 2026 at 7:34 am

    You could group by the cashier and the day:

    select     cashier_id
    ,          dateadd(d, 0, datediff(d, 0, [datetime]))
    ,          sum(grand_total)
    ,          sum(num_people_party)
    from       invoice_totals
    where      [datetime] >= '2012-06-01'
    group by
               cashier_id
    ,          dateadd(d, 0, datediff(d, 0, [datetime]))
    

    In SQL Server 2008 and later, you can replace

    dateadd(d, 0, datediff(d, 0, [datetime]))
    

    with

    cast([datetime] as date)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

New to SQL Server and not very well-versed in how things run with it.
I'm very new to creating installers. This application needs to connect to a SQL
I'm trying to translate this SQL sentence to LINQ but I'm very new in
Please I am very new to PDO, rather a novice at PHP as well.
I'm very new to Sql, and having trouble wrapping my brain around the syntax.
I am very new to SQL and i need to retreive a number of
I am very new to sql.The actual problem is much bigger. I need information
I am very new to using SQL and I haven't been able to find
I am working on a rather large SQL script to be used with Oracle,
I am very new to sql querys and I am looking for a way

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.