<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1250">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7638.1">
<TITLE>RE: [Zope-DB] ZSQL </TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->

<P><FONT SIZE=2>Thanks for the reply.&nbsp; This should get me pointed down a path. </FONT>
</P>

<P><FONT SIZE=2>FYI</FONT>

<BR><FONT SIZE=2>I'm connecting to AS400 DB2 via ODBC.</FONT>
</P>

<P><FONT SIZE=2>Thanks again.</FONT>

<BR><FONT SIZE=2>Israel</FONT>
</P>
<BR>

<P><FONT SIZE=2>-----Original Message-----</FONT>

<BR><FONT SIZE=2>From: zope-db-bounces@zope.org [<A HREF="mailto:zope-db-bounces@zope.org">mailto:zope-db-bounces@zope.org</A>]On</FONT>

<BR><FONT SIZE=2>Behalf Of Dieter Fischer</FONT>

<BR><FONT SIZE=2>Sent: Monday, April 17, 2006 5:57 PM</FONT>

<BR><FONT SIZE=2>To: zope-db@zope.org</FONT>

<BR><FONT SIZE=2>Subject: RE: [Zope-DB] ZSQL </FONT>
</P>
<BR>

<P><FONT SIZE=2>Hello</FONT>
</P>

<P><FONT SIZE=2>This is a SQL problem. So it depends what kind of DB you're using. In Oracle</FONT>

<BR><FONT SIZE=2>you could do something like this (copied from orafaq):</FONT>
</P>

<P><FONT SIZE=2>SELECT&nbsp; *</FONT>

<BR><FONT SIZE=2>FROM&nbsp; (</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2>SELECT&nbsp; job,</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2>sum(decode(deptno,10,sal)) DEPT10,</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2>sum(decode(deptno,20,sal)) DEPT20,</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2>sum(decode(deptno,30,sal)) DEPT30,</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2>sum(decode(deptno,40,sal)) DEPT40</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2>FROM&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; scott.emp</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2>GROUP BY &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; job</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2>)</FONT>

<BR><FONT SIZE=2>ORDER BY 1;</FONT>
</P>

<P><FONT SIZE=2>you can change it to your needs. But this doesn't help, when you have a</FONT>

<BR><FONT SIZE=2>variabe amount of rows (in your case transX). In this case you have to write</FONT>

<BR><FONT SIZE=2>something in PL/SQL (Oracle), plpgsql (PostgreSQL) or whatever your DB is</FONT>

<BR><FONT SIZE=2>programmed with, or write a Python Script in Zope (not fast, but portable).</FONT>
</P>

<P><FONT SIZE=2>Regards</FONT>
</P>

<P><FONT SIZE=2>Dieter</FONT>
</P>

<P><FONT SIZE=2>&gt; -----Original Message-----</FONT>

<BR><FONT SIZE=2>&gt; From: zope-db-bounces@zope.org</FONT>

<BR><FONT SIZE=2>&gt; [<A HREF="mailto:zope-db-bounces@zope.org">mailto:zope-db-bounces@zope.org</A>]On Behalf Of Israel Carr</FONT>

<BR><FONT SIZE=2>&gt; Sent: Monday, April 17, 2006 10:17 PM</FONT>

<BR><FONT SIZE=2>&gt; To: zope-db@zope.org</FONT>

<BR><FONT SIZE=2>&gt; Subject: [Zope-DB] ZSQL</FONT>

<BR><FONT SIZE=2>&gt;</FONT>

<BR><FONT SIZE=2>&gt;</FONT>

<BR><FONT SIZE=2>&gt; I have a table with the columns:</FONT>

<BR><FONT SIZE=2>&gt; id, username, trans_type</FONT>

<BR><FONT SIZE=2>&gt;</FONT>

<BR><FONT SIZE=2>&gt; Sample records:</FONT>

<BR><FONT SIZE=2>&gt; 1,user1,trans1</FONT>

<BR><FONT SIZE=2>&gt; 2,user1,trans3</FONT>

<BR><FONT SIZE=2>&gt; 3,user2,trans4</FONT>

<BR><FONT SIZE=2>&gt; 4,user2,trans2</FONT>

<BR><FONT SIZE=2>&gt; 5,user1,trans1</FONT>

<BR><FONT SIZE=2>&gt; 6,user2,trans3</FONT>

<BR><FONT SIZE=2>&gt;</FONT>

<BR><FONT SIZE=2>&gt;</FONT>

<BR><FONT SIZE=2>&gt; I would like to generate output that contains the username and the</FONT>

<BR><FONT SIZE=2>&gt; total(count) number of each trans_type.&nbsp; Would also like to have a total</FONT>

<BR><FONT SIZE=2>&gt; of all trans_type.</FONT>

<BR><FONT SIZE=2>&gt; Roughly:</FONT>

<BR><FONT SIZE=2>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; trans1&nbsp; trans2&nbsp; trans3&nbsp; trans4</FONT>

<BR><FONT SIZE=2>&gt; user1&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0</FONT>

<BR><FONT SIZE=2>&gt; user2&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1</FONT>

<BR><FONT SIZE=2>&gt;&nbsp;&nbsp;&nbsp; TOTAL&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1</FONT>

<BR><FONT SIZE=2>&gt;</FONT>

<BR><FONT SIZE=2>&gt;</FONT>

<BR><FONT SIZE=2>&gt; I have a ZSQL method with the following:</FONT>

<BR><FONT SIZE=2>&gt; select COUNT(*)</FONT>

<BR><FONT SIZE=2>&gt; from table</FONT>

<BR><FONT SIZE=2>&gt; where trans_type = &lt;dtml-sqlvar transtype type=string&gt;</FONT>

<BR><FONT SIZE=2>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; and username = &lt;dtml-sqlvar username type=string&gt;</FONT>

<BR><FONT SIZE=2>&gt;</FONT>

<BR><FONT SIZE=2>&gt; When testing and feeding parameters it does give me the count for one</FONT>

<BR><FONT SIZE=2>&gt; user and one transaction type.</FONT>

<BR><FONT SIZE=2>&gt;</FONT>

<BR><FONT SIZE=2>&gt;</FONT>

<BR><FONT SIZE=2>&gt; How can I create the desired output and have a general enough ZSQL</FONT>

<BR><FONT SIZE=2>&gt; Method that I can feed these parameters?&nbsp; I've been playing with some</FONT>

<BR><FONT SIZE=2>&gt; &lt;dtml-in&gt; tags and trying to call the ZSQL method but am not really sure</FONT>

<BR><FONT SIZE=2>&gt; how to pass parameters or if I'm way out in left field.&nbsp; Would I need to</FONT>

<BR><FONT SIZE=2>&gt; call the ZSQL method 8+ times to generate output like the table above?</FONT>

<BR><FONT SIZE=2>&gt;</FONT>

<BR><FONT SIZE=2>&gt; I can do pretty basic form inputs into database and selects out based on</FONT>

<BR><FONT SIZE=2>&gt; form or static values but this is a little more complex for me.&nbsp; Any</FONT>

<BR><FONT SIZE=2>&gt; help would be appreciated.</FONT>

<BR><FONT SIZE=2>&gt;</FONT>

<BR><FONT SIZE=2>&gt; Israel</FONT>

<BR><FONT SIZE=2>&gt;</FONT>

<BR><FONT SIZE=2>&gt; _______________________________________________</FONT>

<BR><FONT SIZE=2>&gt; Zope-DB mailing list</FONT>

<BR><FONT SIZE=2>&gt; Zope-DB@zope.org</FONT>

<BR><FONT SIZE=2>&gt; <A HREF="http://mail.zope.org/mailman/listinfo/zope-db">http://mail.zope.org/mailman/listinfo/zope-db</A></FONT>

<BR><FONT SIZE=2>&gt; --</FONT>

<BR><FONT SIZE=2>&gt; No virus found in this incoming message.</FONT>

<BR><FONT SIZE=2>&gt; Checked by AVG Free Edition.</FONT>

<BR><FONT SIZE=2>&gt; Version: 7.1.385 / Virus Database: 268.4.2/314 - Release Date: 16.04.2006</FONT>

<BR><FONT SIZE=2>&gt;</FONT>

<BR><FONT SIZE=2>--</FONT>

<BR><FONT SIZE=2>No virus found in this outgoing message.</FONT>

<BR><FONT SIZE=2>Checked by AVG Free Edition.</FONT>

<BR><FONT SIZE=2>Version: 7.1.385 / Virus Database: 268.4.2/314 - Release Date: 16.04.2006</FONT>
</P>

<P><FONT SIZE=2>_______________________________________________</FONT>

<BR><FONT SIZE=2>Zope-DB mailing list</FONT>

<BR><FONT SIZE=2>Zope-DB@zope.org</FONT>

<BR><FONT SIZE=2><A HREF="http://mail.zope.org/mailman/listinfo/zope-db">http://mail.zope.org/mailman/listinfo/zope-db</A></FONT>
</P>

</BODY>
</HTML>