Solved

Output report with coldfusion

Posted on 2012-12-20
5
163 Views
Last Modified: 2013-01-24
I have a table with some columns: "UnQID" "UserID" "CompDate" "ModDate"

I would like to output a query that will show a list of UserIDs and a count of how many CompDates or Moddates they appear in for a given timespan. Could someone assist?

I would provide the date range into a query in a cfc with arguments. I'd like it to display a YTD or a given range. Any ideas?

It would look something like this:

Month: Dec
-----------
Ralph      25
Jonathan 75
Roberto   58
0
Comment
Question by:earwig75
  • 3
  • 2
5 Comments
 
LVL 25

Expert Comment

by:dgrafx
ID: 38745266
How do you mean - "how many comp dates or mod dates they appear in"?
What is an example value for your compdate and moddate columns?
Can you post a couple example rows with values for each column?
Thanks.
0
 

Author Comment

by:earwig75
ID: 38745310
Basically you can think of them as orders. How many orders does each person complete a day. ModDate is the date an order is created. CompDate is a date the order is completed.

I'd like to a table to show how many were created by each person based on those dates.
0
 
LVL 25

Accepted Solution

by:
dgrafx earned 500 total points
ID: 38745440
First off we can create a couple date vars so you can send in dates from your front end language. You could just replace the date string in single quotes 'Apr 1, 2012' with a CF variable.
Or whatever you want to do ...

Try something like this:

Declare @Sdate DateTime, @Edate DateTime
SET @Sdate = Convert(Date,'Apr 1, 2012')
SET @Edate = Convert(Date,'Apr 30, 2012')

SELECT UserID, (Select count(a.UserID) FROM YourTable a WITH (NOLOCK) Where a.UserID = YourTable.UserID) as count
FROM YourTable WITH (NOLOCK)
WHERE
CompDate BETWEEN @Sdate and @Edate
OR
ModDate BETWEEN @Sdate and @Edate
Group by UserID
Order by UserID
0
 

Author Comment

by:earwig75
ID: 38745498
So I can use declare in a cfquery?
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 38745515
yes
I'm in the habit of doing it this way so that I can create a stored procedure and send in var values to it that originally may be CF vars.

If you are doing a CF Query right on the same page as your code you could just simplify and do something like :
BETWEEN #CreateODBCDateTime(Sdate)# and #CreateODBCDateTime(Edate)#

and in this case Sdate would be a CF variable you've sent in i.e. Apr 1, 2012
I just prefer my method even if the query is on the same page - seems cleaner - but it is your choice - you are the developer!
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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