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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:40:46+00:00 2026-05-15T14:40:46+00:00

I’m using SQL-Server 2005. I have two tables Users and Payments which has a

  • 0

I’m using SQL-Server 2005.

I have two tables Users and Payments which has a foreign key to Users.
Both Users and Payments have a date column (Users set their value during registration and Payments gets a value during payment). Users has a column called isPaymentsRecurring as bit which tells me to renew the user or not. The value is 1 on default = recurring. Payments has a column called paymentSum as tinyint where I insert the value of payment. ( first payment is equal to recurring one)

I need to get a few statistics about that for simple line chart, grouped by date. To separate single days I use the hack below to get whole day as a single item.

Day hack

dateadd(dd,datediff(dd,0,date),0)

What I need to get are the values below all must be grouped by day hack.

1.Unique users in system per day

2.Users that ordered once and then set isPaymentRecurring to 0.

3.Sum of paymentSum per day

4.How many users got recurring payment per day. This means orders of user per day except first order in system.

Thanks, I have queries that work but they don’t work as I want them to thus I want pros opinion on that.

  • 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-05-15T14:40:47+00:00Added an answer on May 15, 2026 at 2:40 pm

    You could add computed columns to your Payments and Users tables that represent the day, month and year of payment or user registration:

    ALTER TABLE dbo.Payments
       ADD PaymentDay AS DAY(PaymentDate) PERSISTED,
       PaymentMonth AS MONTH(PaymentDate) PERSISTED,
       PaymentYear AS YEAR(PaymentDate) PERSISTED
    

    Now these columns give you INT values for the day, month and year and you can easily query them. Since they’re persisted, they can even be indexed!

    You can easily group your payments by those columns now:

    SELECT (list of fields), COUNT(*)
    FROM dbo.Payments
    GROUP BY PaymentYear, PaymentMonth, PaymentDay
    

    or whatever you need to do. With this approach, you can also easily do stats on a per-month basis, e.g. sum up all payments and group by month.

    Update: ok, so you need to understand how to create those queries:

    • Unique users in system per day

      SELECT UserDay, UserMonth, UserYear, COUNT(*) 
      FROM dbo.Users
      GROUP BY UserDay, UserMonth, UserYear
      

      That would count the users and group them by day, month, year

    • Users that ordered once and then set isPaymentRecurring to 0.

      SELECT UserDay, UserMonth, UserYear, COUNT(*) 
      FROM dbo.Users
      WHERE isPaymentRecurring = 0
      GROUP BY UserDay, UserMonth, UserYear
      

      Is that what you’re looking for?? Number of users grouped by day/month/year that have their isPaymentRecurring set to 0 ?

    • sum of paymentSum per day

      SELECT PaymentDay, PaymentMonth, PaymentYear, SUM(PaymentSum)
      FROM dbo.Payments
      GROUP BY PaymentDay, PaymentMonth, PaymentYear
      

      That would sum up the PaymentSum column and group it by day, month, year

    I don’t really understand what you’re trying to achieve with the other two queries, and what criteria would have to apply for those queries.

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

Sidebar

Ask A Question

Stats

  • Questions 448k
  • Answers 448k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There is a new open source project that provides support… May 15, 2026 at 7:49 pm
  • Editorial Team
    Editorial Team added an answer I suggest developing in a single browser, then testing your… May 15, 2026 at 7:49 pm
  • Editorial Team
    Editorial Team added an answer The databases would be logically related, but not actually related… May 15, 2026 at 7:49 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.