Solved

Cold Fusion cfquery output from a Pivot

Posted on 2004-09-14
6
903 Views
Last Modified: 2012-06-21
I am relatively new to Cold Fusion Studio 5. I have had success with hundreds of pages serving up on our company intranet.. but..
I wish to output the results of my SQL crosstab (pivot) query in Cold fusion

I am happy with how the sql query looks in MSAccess

But I need the cold fusion code to output this. I'll supply the code if you like .. max points

 
0
Comment
Question by:Warez_Willy
  • 3
  • 2
6 Comments
 
LVL 4

Expert Comment

by:willcode4coffee
ID: 12179644
Yes, please post the code for this query.
0
 

Author Comment

by:Warez_Willy
ID: 12185415
OK here is my sql statement from msaccess

TRANSFORM Count(Stock.TicketNumber) AS CountOfTicketNumber
SELECT Stock.Length
FROM (Categories INNER JOIN StockDescription ON Categories.CategoryID = StockDescription.CategoryID) INNER JOIN Stock ON StockDescription.StockDescriptionID = Stock.StockDescription
WHERE (((Categories.CategoryID)=14) AND ((Stock.StatusUsed)=0) AND ((Stock.Location)='ASH'))
GROUP BY Categories.Category, Stock.Length, Categories.CategoryID, Stock.StatusUsed, Stock.Location
ORDER BY Stock.Length
PIVOT StockDescription.StockDescription;


I'd like the results of this cross tab in a grid format in cold fusion. Thanks very much.
0
 

Expert Comment

by:nicky2k
ID: 12285432
Please confirm, do you want a CF tabular grid or a graphical grid?

A table is easy, use CF arrays.

<cfset myArray=ArrayNew(2)> <!--creates 2 dimensional array-->

<cfoutput query="yourqueryname">
<cfset myArray[1][#CurrentRow#]=#yourqueryname.StockCategory#>
<cfset myArray[2][#CurrentTow#]=#yourqueryname.StockDescription#>
</cfoutput>

<!--note that CurrentRow is a valid cfoutput query variable that just dynamically calculates the current row of the record you are retreiving--->

If you are after multidimensional sort of grid (I need you to explain precisely here), you might want to do an array of arrays or use structures.

Nicky.

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:Warez_Willy
ID: 12293294
Thanks nicky2k i believe arrays are the direction i need to go. But my problem still isn't resolving using your suggestion(ps ..."currentTow" is a typo yes?)

I feel a bit thick here... but, do I use the same query I posted (ie the pivot type, or do I use a simpler SELECT query and let the CF "array" function sort it out?

If so I would have a query consisting of 3 columns

StockDescription - Length - Countofticketnumber

I would like the results in a grid if possible.
where Length is the row heading, Stockdescription is the column heading and countofticketnumber is the data
0
 

Accepted Solution

by:
nicky2k earned 500 total points
ID: 12295656
Yes, CurrentTow is a typo, it should be Current Row.

If you wanted a graphical grid, then use <CFgrid>.  You need to be doing something like this:-

<!--- This example shows the cfgrid, cfgridCOLUMN, cfgridROW,
and cfgridUPDATE tags in action --->

<!--- use a query to show the useful qualities of cfgrid --->

<!--- If the gridEntered form field has been tripped,
perform the gridupdate on the table specified in the database.
Using the default value keyonly=yes allows us to change only
the information that differs from the previous grid --->
<CFIF IsDefined("form.gridEntered") is True>
<cfgridUPDATE GRID="FirstGrid" DATASOURCE="yourdatasource"
TABLENAME="Stocks"  KEYONLY="Yes">
</CFIF>


<cfquery name="yourqueryname" datasource="yourdatasource">
SELECT Stock.Length, Count(Stock.TicketNumber) AS CountOfTicketNumber,StockDescription.StockDescription
FROM (Categories INNER JOIN StockDescription ON Categories.CategoryID = StockDescription.CategoryID) INNER JOIN Stock ON StockDescription.StockDescriptionID = Stock.StockDescription
WHERE (((Categories.CategoryID)=14) AND ((Stock.StatusUsed)=0) AND ((Stock.Location)='ASH'))
GROUP BY Categories.Category, Stock.Length, Categories.CategoryID, Stock.StatusUsed, Stock.Location
ORDER BY Stock.Length
</cfquery>

<HTML>
<HEAD>
<TITLE>
cfgrid Example
</TITLE>
</HEAD>

<BODY>
<H3>cfgrid Example</H3>

<I>Try adding stock to the database, and then deleting it.</I>
<!--- call the CFFORM to allow us to use cfgrid controls --->
<CFFORM ACTION="yourpage.cfm" METHOD="POST" ENABLECAB="Yes">

<!--- We include Course_ID in the cfgrid, but do not allow
for its selection or display --->
<!--- cfgridCOLUMN tags are used to change the parameters
involved in displaying each data field in the table--->

<cfgrid NAME="FirstGrid" WIDTH="450"
    QUERY="yourqueryname" INSERT="Yes"
    DELETE="Yes" SORT="Yes"
    FONT="Tahoma" BOLD="No" ITALIC="No"
    APPENDKEY="No" HIGHLIGHTHREF="No"
    GRIDDATAALIGN="LEFT" GRIDLINES="Yes"
    ROWHEADERS="Yes" ROWHEADERALIGN="LEFT"
    ROWHEADERITALIC="No" ROWHEADERBOLD="No"
    COLHEADERS="Yes" COLHEADERALIGN="LEFT"
    COLHEADERITALIC="No" COLHEADERBOLD="No"
    SELECTCOLOR="Red" SELECTMODE="EDIT"
    PICTUREBAR="No" INSERTBUTTON="To insert"
    DELETEBUTTON="To delete" SORTASCENDINGBUTTON="Sort ASC"
    SORTDESCENDINGBUTTON="Sort DESC">
      <cfgridCOLUMN NAME="Length" HEADER="Stock Length"
        HEADERALIGN="LEFT" DATAALIGN="LEFT"
        BOLD="Yes" ITALIC="No"
        SELECT="Yes" DISPLAY="Yes"
        HEADERBOLD="No" HEADERITALIC="Yes">
    <cfgridCOLUMN NAME="Description" HEADER="Description"
        HEADERALIGN="LEFT" DATAALIGN="LEFT"
        BOLD="No" ITALIC="No"
        SELECT="Yes" DISPLAY="Yes"
        HEADERBOLD="No" HEADERITALIC="No">
    <cfgridCOLUMN NAME="CountOfTicketNumber" HEADER="Count"
        HEADERALIGN="LEFT" DATAALIGN="LEFT"
        FONT="Times" BOLD="No"
        ITALIC="No" SELECT="Yes"
        DISPLAY="Yes" HEADERBOLD="No"
        HEADERITALIC="No">
</cfgrid>

</cfform>

That is the general idea. You may have to read up on the <CFGrid> tag, use help,Open Help References Window  and then type cfgrid in the text box in your CF Studio. You will find that information very useful, play around with the examples they give.

Hope that helps.

Nicky.
0
 

Expert Comment

by:nicky2k
ID: 12295693
By the way, COURSE_ID should say Stock_ID.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
need some regex help 15 27
Create and populate iFrame onClick of a button? 1 64
WCAG (Web Content Accessibility Guidelines) levels 3 70
.php tree directory? 5 57
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to dynamically set the form action using jQuery.

861 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now