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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:00:43+00:00 2026-05-16T08:00:43+00:00

Hello everyone i have big query to calculation and counter by clinic ID SELECT

  • 0

Hello everyone i have big query to calculation and counter by clinic ID

SELECT nc.ID AS ClinicID, nc.Name AS ClinicName, 
       SUM(cr.CountRecept * cs.Price) AS TotalPriceService, SUM(cr.TotalPaid) AS TotalPaid, 
       SUM(cs.Price * cr.Company_Percentage / 100) AS TotalInsurance, 
       SUM(cr.CountRecept) AS TotalCountRecept
FROM ClinicsServices AS cs INNER JOIN
       (SELECT  tc.Date_Write, COUNT(ID) AS CountRecept, Clinic_Service_ID,  
        company_Percentage, Company_ID, SUM(Paid_Patient) AS TotalPaid
        FROM dbo.TicketsClinics AS tc WHERE  (Status = 1) 
        GROUP BY Clinic_Service_ID, Company_Percentage, Company_ID, tc.Date_Write) AS cr ON  
        cs.ID = cr.Clinic_Service_ID INNER JOIN
       (SELECT  ID, NAME FROM dbo.Clinics AS c GROUP BY ID, Name) AS nc ON cs.Clinic_ID = c.ID
GROUP BY nc.Name, nc.ID

it is true query but i want add between date

 AND tc.Date_Write BETWEEN tc.Date_Write AND tc.Date_Write

in subquery

 Select tc.Date_Write
 Group by tc.Date_Write

in main query

like this

   SELECT nc.ID AS ClinicID, nc.Name AS ClinicName, 
          SUM(cr.CountRecept * cs.Price) AS TotalPriceService, 
          SUM(cr.TotalPaid) AS TotalPaid, 
          SUM(cs.Price * cr.Company_Percentage / 100) AS TotalInsurance, 
          SUM(cr.CountRecept) AS TotalCountRecept, cr.Date_Write
   FROM dbo.ClinicsServices AS cs INNER JOIN
          (SELECT tc.Date_Write, COUNT(ID) AS CountRecept, Clinic_Service_ID,  
                  Company_Percentage, Company_ID, SUM(Paid_Patient) AS TotalPaid
           FROM dbo.TicketsClinics AS tc
           WHERE  (Status = 1) AND tc.Date_Write BETWEEN tc.Date_Write AND tc.Date_Write 
           GROUP BY Clinic_Service_ID, Company_Percentage, Company_ID, tc.Date_Write) 
                     AS cr ON cs.ID = cr.Clinic_Service_ID 
           INNER JOIN (SELECT  ID, NAME FROM dbo.Clinics AS c GROUP BY ID, Name) 
                              AS nc ON  cs.Clinic_ID = nc.ID
           GROUP BY nc.Name, nc.ID, cr.Date_Write

it is false query why because it is display every receipt but i want display
1 – TotalPriceService
2 – TotalPaid
3 – TotalInsurance
4 – TotalCounterReceipt
5 – FromDate
6 – ToDate

the true query that returns calculation and counter i want add search by date i know the second query it is wrong but i want search by date BETWEEN tc.Date_Write FROMDATE AND TODATE how do this thank you for help me

  • 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-16T08:00:44+00:00Added an answer on May 16, 2026 at 8:00 am

    Your BETWEEN clause checks whether a date is between itself. This will return true for every record.

    To use BETWEEN correctly, you need to supply two other dates. This query seems like a candidate for a stored procedure that has two date parameters, a “from” date and a “to” date, like this:

    CREATE PROCEDURE usp_GetClinicStats(
        @FromDate DATETIME,
        @ToDate DATETIME
        )
    AS
    BEGIN
      SELECT nc.ID AS ClinicID, nc.Name AS ClinicName, 
              SUM(cr.CountRecept * cs.Price) AS TotalPriceService, 
              SUM(cr.TotalPaid) AS TotalPaid, 
              SUM(cs.Price * cr.Company_Percentage / 100) AS TotalInsurance, 
              SUM(cr.CountRecept) AS TotalCountRecept, cr.Date_Write
       FROM dbo.ClinicsServices AS cs INNER JOIN
              (SELECT tc.Date_Write, COUNT(ID) AS CountRecept, Clinic_Service_ID,  
                      Company_Percentage, Company_ID, SUM(Paid_Patient) AS TotalPaid
               FROM dbo.TicketsClinics AS tc
               WHERE Status = 1
                 AND tc.Date_Write BETWEEN CONVERT(VARCHAR, @FromDate, 111) AND CONVERT(VARCHAR, @ToDate, 111) 
               GROUP BY Clinic_Service_ID, Company_Percentage, Company_ID, tc.Date_Write) 
                         AS cr ON cs.ID = cr.Clinic_Service_ID 
               INNER JOIN (SELECT  ID, NAME FROM dbo.Clinics AS c GROUP BY ID, Name) 
                                  AS nc ON  cs.Clinic_ID = nc.ID
               GROUP BY nc.Name, nc.ID, cr.Date_Write
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So hello everyone I have a big problem right now with a button that
Hello everyone I have a problem. I want to do a GridView with a
Hello everyone Masters Of Web Delevopment :) I have a piece of PHP script
Hello everyone, I have some confusion regarding some Win32 API data types and macros
Hello again everyone, This time I have a problem with Intent & Extras. here's
Hello everyone i have a problem in my application. The check in my check
Hello everyone I would have a value for the need to save every time
Hello everyone i currently have this: import feedparser d = feedparser.parse('http://store.steampowered.com/feeds/news.xml') for i in
Introduction : Hello Everyone, I have been looking for days for a way to
Hello everyone in wordpress I was wondering how to QUERY the POST TITLE and

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.