Google Answers Logo
View Question
 
Q: ColdFusion / SQL Query ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: ColdFusion / SQL Query
Category: Computers > Internet
Asked by: belac-ga
List Price: $10.00
Posted: 08 Dec 2003 07:09 PST
Expires: 07 Jan 2004 07:09 PST
Question ID: 284711
I need the SQL query and example  of coldfusion output for below:

Coldfusion/SQL question. I have a table in my database named "ProductSearch"
in which I need to grab all the text words from the "words" field and display
how many times each EXACT word is present in the table. Example below:


     Product Search Table
===============================
|ID |    Word    | Date Added |
===============================
| 1 | CD Player  | 11/2/2003  |
| 2 | CVD Player | 11/2/2003  |
| 3 | Television | 11/2/2003  |
| 4 | VCR Remote | 11/3/2003  |
| 5 | Cable Box  | 11/2/2003  |
| 6 | Televison  | 11/2/2003  |
| 7 | Cable Box  | 11/7/2003  |
| 8 | Headphones | 11/7/2003  |
| 9 | Television | 11/12/2003 |
===============================


I need to ouptut it on a coldfusion page so it would look like this for
all the records in the database:


Word             Exact Times Present

CD Player              1
CVD Player             1
Television             3
VCR Remote             1
Cable Box              2
Headphones             1
Answer  
Subject: Re: ColdFusion / SQL Query
Answered By: joseleon-ga on 08 Dec 2003 10:23 PST
Rated:5 out of 5 stars
 
Hello, belac:

This is the coldfusion code to insert into your ColdFusion page:

<table width="85%" bgcolor="#999999" border="0" cellpadding="0" cellspacing="0">
<cfquery name="product_query" DBType="query">
	SELECT *, count(ID) as Times
	FROM ProductSearch
	GROUP BY Word
</cfquery>

		<tr>
			<td bgcolor="white"><b>Word</b></td>
			<td bgcolor="white"><b>Times</b></td>
		</tr>
	<cfoutput query="product_query">
		<tr>
			<td valign="top" bgcolor="white">#Word#</td>
			<td valign="top" bgcolor="white">#Times#</td>
		</tr>
	</cfoutput>
</table>

If you have any problem integrating it, please, don't hesitate to
request for any clarification, I'm here to help you until you get what
you need.

Regards.

Request for Answer Clarification by belac-ga on 08 Dec 2003 11:25 PST
Hello joseleon,

Thank you for your prompt reply. However I receive the following error
when I run the code:

Here is my query written in the format you sent. The table and fields
are named different, but contain the same as my orginal post:

<cfquery name="search_queries" datasource="#ds#">
  SELECT *, count(QueryID) AS QueryCount
  FROM MasQueries
  GROUP BY QueryTerm
</cfquery>


I receive the following error:

Error Executing Database Query.  
[Macromedia][SQLServer JDBC Driver][SQLServer]Column
'MasQueries.QueryID' is invalid in the select list because it is not
contained in either an aggregate function or the GROUP BY clause.

The QueryID is the same as the ID field in my orginal post. It is the
Primary Key (INT TYPE) for each record.

Clarification of Answer by joseleon-ga on 08 Dec 2003 11:29 PST
Hello, belac:
 Ok, is there any way you can post/export your database table so I can
test it here with the real table description? If not, just tell me and
I will try to reproduce the problem here.

Regards.

Clarification of Answer by joseleon-ga on 08 Dec 2003 12:06 PST
Hello, belac:
  Try with this SQL instead:

SELECT QueryTerm,  count(QueryID) as QueryCount
FROM MasQueries
Group by QueryTerm

it works in Access, I'm going to try with an SQL Server table.

Regards.

Request for Answer Clarification by belac-ga on 08 Dec 2003 12:11 PST
Can Iu email you or can I post my email address so I can give you the
FTP info to grab the file?

Clarification of Answer by joseleon-ga on 08 Dec 2003 12:21 PST
Hello, belac:
  No, I'm sorry, we can't communicate privately due the Researcher
Guidelines and Google Terms of Service that prevent us to do so.

Please, try my last query because I have just tested it on SQL server
and it works ok. If it still doesn't work I will post here a private
upload page for you to upload the database so I can work on it, but
first, please, try the last query as the upload method is the last
resort.

Regards.

Request for Answer Clarification by belac-ga on 08 Dec 2003 12:34 PST
Hello Jose,

Thanks, it worked. However, since I can't use the primary key
"QueryID" to number the records in the output how can I display the
recordcount for the query next to each record?

Like:

1. CD player   2
2. Television  3
3. MP3 Player  1
4. DVD Player  4

etc...

Clarification of Answer by joseleon-ga on 08 Dec 2003 12:54 PST
Hello, belac:
  If you use the cfoutput tag, you can use the CurrentRow var that is
set to the number of the row is being echoed to the browser:

	<cfoutput query="a">
		<tr>
			<td valign="top" bgcolor="white">#CurrentRow#</td>			<td
valign="top" bgcolor="white">#QueryTerm#</td>
			<td valign="top" bgcolor="white">#QueryCount#</td>
		</tr>
	</cfoutput>

I hope this is what you were looking for.

Regards.

Request for Answer Clarification by belac-ga on 08 Dec 2003 13:38 PST
Great, thanks for all your help. How can I find you again for
questions in the future? I need fast response time like this.

Clarification of Answer by joseleon-ga on 08 Dec 2003 15:02 PST
Hello, belac:
  That's very kind of you, you can post questions directly to me by
using "For joseleon only" as subject.

Regards.
belac-ga rated this answer:5 out of 5 stars and gave an additional tip of: $5.00
Excellent service, fast and responsive.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy