Solved

get count

Posted on 2008-06-16
6
207 Views
Last Modified: 2010-04-21
based on the query below, i now need to add to it and get a count of how many is in each day

example
Mon/16 (5)  <---- 5 is the count of how many Mon 16 is in the query
Sat/14 (3)

below produces

Mon/16
Sat/14

        SELECT  distinct CONVERT(VARCHAR(10), TIMEDATE , 120) as varDate
        FROM orders
        WHERE year(TIMEDATE)  = YEAR('#datepassed#')
        AND month(TIMEDATE)  = month('#datepassed#')
        ORDER BY varDate DESC
0
Comment
Question by:pigmentarts
  • 3
  • 2
6 Comments
 
LVL 60

Accepted Solution

by:
chapmandew earned 400 total points
ID: 21796734
       SELECT  CONVERT(VARCHAR(10), TIMEDATE , 120) as varDate, count(*)
        FROM orders
        WHERE year(TIMEDATE)  = YEAR('#datepassed#')
        AND month(TIMEDATE)  = month('#datepassed#')
        group by CONVERT(VARCHAR(10), TIMEDATE , 120)
0
 
LVL 12

Author Comment

by:pigmentarts
ID: 21796805
what is the variable for count so i can output it?  varDate  (which i need) gives me the date not the count
0
 
LVL 31

Assisted Solution

by:James Murrell
James Murrell earned 100 total points
ID: 21796846
 SELECT  CONVERT(VARCHAR(10), TIMEDATE , 120) as varDate, count(*)as countnumber
        FROM orders
        WHERE year(TIMEDATE)  = YEAR('#datepassed#')
        AND month(TIMEDATE)  = month('#datepassed#')
        group by CONVERT(VARCHAR(10), TIMEDATE , 120)

I think
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 12

Author Comment

by:pigmentarts
ID: 21796855
ok seems to work with the following is this ok code?

       SELECT  CONVERT(VARCHAR(10), TIMEDATE , 120) as varDate, count(order_id) as varCount
        FROM orders
        WHERE year(TIMEDATE)  = YEAR('#datepassed#')
        AND month(TIMEDATE)  = month('#datepassed#')
        group by CONVERT(VARCHAR(10), TIMEDATE , 120)
       ORDER BY varDate DESC
0
 
LVL 31

Expert Comment

by:James Murrell
ID: 21796867
yes, but note chapmandew did the hard work...
0
 
LVL 12

Author Closing Comment

by:pigmentarts
ID: 31467736
thanks both of you
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

823 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question