<?xml version="1.0" encoding="utf-8"?>

			<rss version="2.0" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cc="http://web.resource.org/cc/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">

			<channel>
			<title>Boyzoid&apos;s Blog &amp; Stuff - Database Stuff</title>
			<link>http://www.boyzoid.com/blog/index.cfm</link>
			<description>The Ramblings of a ganius</description>
			<language>en-us</language>
			<pubDate>Tue, 07 Sep 2010 18:59:59 -0400</pubDate>
			<lastBuildDate>Sun, 17 Sep 2006 12:55:00 -0400</lastBuildDate>
			<generator>BlogCFC</generator>
			<docs>http://blogs.law.harvard.edu/tech/rss</docs>
			<managingEditor>scott@boyzoid.com</managingEditor>
			<webMaster>scott@boyzoid.com</webMaster>
			<itunes:subtitle></itunes:subtitle>
			<itunes:summary></itunes:summary>
			<itunes:category text="Technology" />
			<itunes:category text="Technology">
				<itunes:category text="Podcasting" />
			</itunes:category>
			<itunes:category text="Technology">
				<itunes:category text="Tech News" />
			</itunes:category>
			<itunes:keywords></itunes:keywords>
			<itunes:author></itunes:author>
			<itunes:owner>
				<itunes:email>scott@boyzoid.com</itunes:email>
				<itunes:name></itunes:name>
			</itunes:owner>
			
			<itunes:explicit>no</itunes:explicit>
			
			<item>
				<title>Uber-query clarification.</title>
				<link>http://www.boyzoid.com/blog/index.cfm/2006/9/17/Uberquery-clarification</link>
				<description>
				
				&lt;p&gt;I just got finished listening to this week &lt;a href=&quot;http://www.coldfusionweekly.com/&quot;&gt;ColdFusion Weekly podcast&lt;/a&gt;.&#xa0; I was flattered to hear that &lt;a href=&quot;/blog/index.cfm/2006/8/28/Many-cfqueries-vs-1-Uberquerywhich-is-faster&quot;&gt;this post&lt;/a&gt; was discussed.&#xa0; However, I would like to make some clarifications on my post, and what was discussed.&lt;/p&gt;

&lt;p&gt;First, like Matt (I think it was Matt, its hard for me to tell them apart), I prefer to have the databse do as&#xa0; much work as possible.&#xa0; That was not really possible in the situation I was referring to in my post.&#xa0; In the situation I described, I was inserting or updating data, as much as 10,000 rows at a time. I was &lt;strong&gt;NOT&lt;/strong&gt; retrieving data from the database, looping over the results of that query and performing other queries (typically, that&apos;s what JOINs are for).&lt;/p&gt;

&lt;p&gt;As I pointed out, I am unsure of whether or not the multiple queries was faster due to the use of &amp;lt;cfqueryparam&amp;gt; or not.&#xa0; I also mentioned that I was going to test to see what would happen if i removed the &amp;lt;cfqueryparam&amp;gt; from the multiple queries.&#xa0; Unfortuantely, I am no longer stationed on-site at that client any longer, so that part of the process shall remain a mystery.&lt;/p&gt;

&lt;p&gt;Let me say again, I prefer to let the database do as much work as possible.&#xa0; However, when inserting or updating large sets of data, this may not be the best course of action, and as they guys pointed out, &apos;it depends&apos;.&lt;/p&gt;

&lt;p&gt;Thanx Matt and Peter, keep up the good work.&lt;br/&gt;&lt;/p&gt; 
				</description>
				
				<category>ColdFusion Stuff</category>
				
				<category>Database Stuff</category>
				
				<pubDate>Sun, 17 Sep 2006 12:55:00 -0400</pubDate>
				<guid>http://www.boyzoid.com/blog/index.cfm/2006/9/17/Uberquery-clarification</guid>
				
				
			</item>
			
			<item>
				<title>SUM() cool stuff</title>
				<link>http://www.boyzoid.com/blog/index.cfm/2006/9/14/SUM-cool-stuff</link>
				<description>
				
				&lt;p&gt;One of my personal projects is an on-line &lt;a href=&quot;http://www.movpool.com/&quot;&gt;football pool&lt;/a&gt;
that is run by a fried of mine.&#xa0; The pool is fairly simple, you pick 2
teams each week who you think will have the highest margin of victory
(MOV), the person who has the highest aggregate MOV at the end of the
season wins.&lt;/p&gt;


&lt;p&gt;I was working on a &apos;stats&apos; page yesterday to show information about
the teams chosen by the entrants, as well as MOV information based on
team, conference, division, etc... and ran into a potential issue with
my database structure.&lt;/p&gt;


&lt;p&gt;I have a &apos;game&apos; table, which has the following columns: &lt;font face=&quot;Courier New, Courier, mono&quot;&gt;gameID,
SeasonID, week, homeTeamID, awayTeamID, homeScore, awayScore&lt;/font&gt;.&#xa0; The
potential issue was that for any given week, a team could be in the
awayTeamID column, or the homeTeamID column.&#xa0; It was easy enough to
determine this by using a &lt;font face=&quot;Courier New, Courier, mono&quot;&gt;CASE...WHEN&lt;/font&gt; statement in my SQL. &lt;br/&gt;[code]...&lt;br/&gt;CASE WHEN team.teamID = awayTeamID THEN stuff for away team&lt;br/&gt;ELSE some stuff for home team[/code]&lt;/p&gt;


&lt;p&gt;There
was one problem with this, one of the &apos;reports&apos; I was working on
required the season-long MOV for every team, which means I needed to
use &lt;font face=&quot;Courier New, Courier, mono&quot;&gt;SUM()&lt;/font&gt;.&#xa0; I know I could have handled this in CF, but I prefer to let
the database do what it is good at, and try to avoid unnecessary
processing of data with CF.&lt;/p&gt;


&lt;p&gt;On a whim, I decided to try something rather odd, and surprisingly,
it worked.&#xa0; I tried putting the case statement inside the &lt;font face=&quot;Courier New, Courier, mono&quot;&gt;SUM()&lt;/font&gt; call,
like this.&lt;br/&gt;[code]...&lt;br/&gt;SUM(&lt;br/&gt;&#xa0;&#xa0;&#xa0; CASE WHEN t.teamid = gh.homeTeamID THEN gh.homeScore-gh.awayScore&lt;br/&gt;&#xa0;&#xa0;&#xa0; ELSE gh.awayScore-gh.homeScore&lt;br/&gt;&#xa0;&#xa0;&#xa0; END &lt;br/&gt;&#xa0;&#xa0;&#xa0; ) AS MOV&lt;br/&gt;...[/code]&lt;/p&gt;


&lt;p&gt;Basically
what this does is use the &lt;font face=&quot;Courier New, Courier, mono&quot;&gt;CASE&lt;/font&gt; statement to determine if the team is
the home team, if so, it calculates the MOV as homeScore-awayScore.&#xa0; If
the team is not the home team, they must be the away team, so the MOV
is calculated as awayScore-homeScore.&lt;/p&gt;


&lt;p&gt;I think its pretty cool that you can put logic inside of the &lt;font face=&quot;Courier New, Courier, mono&quot;&gt;SUM()&lt;/font&gt;
call.&#xa0; I have not tested it, but I would imagine you could also add
logic inside other aggregate functions like &lt;font face=&quot;Courier New, Courier, mono&quot;&gt;MAX()&lt;/font&gt; or &lt;font face=&quot;Courier New, Courier, mono&quot;&gt;MIN()&lt;/font&gt;.&lt;br/&gt;&lt;/p&gt; 
				</description>
				
				<category>ColdFusion Stuff</category>
				
				<category>Database Stuff</category>
				
				<pubDate>Thu, 14 Sep 2006 13:39:00 -0400</pubDate>
				<guid>http://www.boyzoid.com/blog/index.cfm/2006/9/14/SUM-cool-stuff</guid>
				
				
			</item>
			</channel></rss>