<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Axelology &#187; SQL</title>
	<atom:link href="http://www.axelscript.com/category/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.axelscript.com</link>
	<description>Axel Jensen on Flex, Coldfusion and... other stuff</description>
	<lastBuildDate>Mon, 14 Jun 2010 17:30:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Using SQL sub select statments, or selects within select statments</title>
		<link>http://www.axelscript.com/2008/02/11/using-sql-sub-select-statments-or-selects-within-select-statments/</link>
		<comments>http://www.axelscript.com/2008/02/11/using-sql-sub-select-statments-or-selects-within-select-statments/#comments</comments>
		<pubDate>Mon, 11 Feb 2008 18:19:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Coldfusion]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.axelscript.com/2008/02/11/using-sql-sub-select-statments-or-selects-within-select-statments/</guid>
		<description><![CDATA[In our team of developer&#8217;s we use a tracking system, to track work orders, bug fixes, feature requests, and the status of those projects&#8230; One of my recent assignments was to create a &#8220;Recently Updated List&#8221; This list will contain the trackID, and a Title&#8230; it will sort by the date in descending order so [...]]]></description>
			<content:encoded><![CDATA[<p class="body">In our team of developer&#8217;s we use a tracking system, to track work orders, bug fixes, feature requests, and the status of those projects&#8230;</p>
<p> One of my recent assignments was to create a &#8220;Recently Updated List&#8221;</p>
<p>This list will contain the trackID, and a Title&#8230; it will sort by the date in descending order so we always see the most recent items first&#8230; It will join 2 tables &#8211; items(v_items), and events&#8230;</p>
<p>Items is the Main table, and Events are details about that item that happen along the tracking of that item&#8230;</p>
<p><span id="more-39"></span><br />
For example, say you have track 897  897<br />
========<br />
(below are events)<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
edited by axel on 11/11/06 @ 2:00pm</p>
<p>We now are finished with this track<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
edited by axel on 11/11/06 @ 1:30pm</p>
<p>We did something else<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
edited by axel on 11/11/06 @ 1:00pm</p>
<p>we edited the table in the database to meet a need<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p class="code"><span style="color: #800000">&lt;cfquery datasource=<span style="color: #0000ff">&#8220;#Application.AdminDsn#&#8221;</span> name=<span style="color: #0000ff">&#8220;getFeaturesList&#8221;</span>&gt;</span><br />
SELECT<br />
v.itemid, v.title,<br />
e.datecreated, e.eventid<br />
FROM v_items v<br />
INNER Join Events e<br />
ON v.itemid = e.itemid<br />
WHERE<br />
e.eventid in (<br />
SELECT TOP 1 e2.eventid<br />
FROM events e2<br />
WHERE e2.itemid = v.itemid<br />
AND e.createdbyuserid = 92<br />
ORDER BY e2.datecreated desc<br />
)<br />
AND<br />
e.datecreated &gt;<br />
<span style="color: #800000">&lt;cfqueryparam cfsqltype=<span style="color: #0000ff">&#8220;cf_sql_date&#8221;</span><br />
value=<span style="color: #0000ff">&#8220;#DateAdd(&#8216;m&#8217;,-1,Now())#&#8221;</span>/&gt;</span><br />
AND v.statusID IN (<span style="color: #0000ff">5</span>)<br />
ORDER BY e.datecreated desc<br />
<span style="color: #800000">&lt;/cfquery&gt;</span></p>
<img src="http://www.axelscript.com/?ak_action=api_record_view&id=39&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.axelscript.com/2008/02/11/using-sql-sub-select-statments-or-selects-within-select-statments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>USING Sql IN with CFQUERYPARAM the list attribute</title>
		<link>http://www.axelscript.com/2008/02/10/using-sql-in-with-cfqueryparam-the-list-attribute/</link>
		<comments>http://www.axelscript.com/2008/02/10/using-sql-in-with-cfqueryparam-the-list-attribute/#comments</comments>
		<pubDate>Sun, 10 Feb 2008 19:21:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Coldfusion]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.axelscript.com/2008/02/10/using-sql-in-with-cfqueryparam-the-list-attribute/</guid>
		<description><![CDATA[I have a page that grabs a list of numbers, either from a series of checkboxes, or a multiple select box, and it passes the Value of the item&#8230; &#60;select name=&#8220;Seminars&#8221; multiple=&#8220;multiple&#8221; size=&#8220;10&#8243;&#62; &#60;cfloop query=&#8220;somequery&#8221;&#62; &#60;option value=&#8220;#seminarid#&#8221;&#62;#title#&#60;/option&#62; &#60;/cfloop&#62; &#60;/select&#62; when you submit the page, and you select multiple items from the box, you&#8217;re going to [...]]]></description>
			<content:encoded><![CDATA[<p class="body">I have a page that grabs a list of numbers, either from a series of checkboxes, or a multiple select box, and it passes the Value of the item&#8230;</p>
<p class="code"><span style="color: #000080"><span style="color: #ff8000">&lt;select name=<span style="color: #0000ff">&#8220;Seminars&#8221;</span> multiple=<span style="color: #0000ff">&#8220;multiple&#8221;</span> size=<span style="color: #0000ff">&#8220;10&#8243;</span>&gt;</span></span><br />
<span style="color: #800000">&lt;cfloop query=<span style="color: #0000ff">&#8220;somequery&#8221;</span>&gt;</span><br />
<span style="color: #000080"><span style="color: #ff8000">&lt;option value=<span style="color: #0000ff">&#8220;#seminarid#&#8221;</span>&gt;</span></span>#title#<span style="color: #000080"><span style="color: #ff8000">&lt;/option&gt;</span></span><br />
<span style="color: #800000">&lt;/cfloop&gt;</span><br />
<span style="color: #000080"><span style="color: #ff8000">&lt;/select&gt;</span></span></p>
<p><span id="more-27"></span><br />
when you submit the page, and you select multiple items from the box, you&#8217;re going to get a list returned back in the form.seminars&#8230; ie. (1,2,3), here you could utilize the list attribute in cfqueryparam to work for you in trying to grab some rows from the database only where what was selected is relevant&#8230;</p>
<p class="code"><span style="color: #800000">&lt;cfquery name=<span style="color: #0000ff">&#8220;qGetSeminarsUsers&#8221;</span> datasource=<span style="color: #0000ff">&#8220;#datadsn#&#8221;</span>&gt;</span><br />
SELECT<br />
su.userid, su.seminarid as id, su.fname, su.lname, su.email<br />
FROM seminarusers su<br />
WHERE su.seminarid IN<br />
(<br />
<span style="color: #800000">&lt;cfqueryparam list=<span style="color: #0000ff">&#8220;yes&#8221;</span><br />
cfsqltype=<span style="color: #0000ff">&#8220;cf_sql_integer&#8221;</span><br />
value=<span style="color: #0000ff">&#8220;#arguments.seminars#&#8221;</span><br />
/&gt;</span><br />
)<br />
<span style="color: #800000">&lt;/cfquery&gt;</span></p>
<p>as a begginer you may try to loop through the list in your query to grab all of the id&#8217;s and use a lot of &#8220;AND&#8221; &#8220;OR&#8221; sql statments in you&#8217;re WHERE clause.  BUT using the &#8220;IN&#8221; clause in conjunction the the list=&#8221;yes&#8221; feature of cfqueryparam, it makes this query a breeze.</p>
<img src="http://www.axelscript.com/?ak_action=api_record_view&id=27&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.axelscript.com/2008/02/10/using-sql-in-with-cfqueryparam-the-list-attribute/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Joins in sql</title>
		<link>http://www.axelscript.com/2008/02/10/using-joins-in-sql/</link>
		<comments>http://www.axelscript.com/2008/02/10/using-joins-in-sql/#comments</comments>
		<pubDate>Sun, 10 Feb 2008 18:59:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.axelscript.com/2008/02/10/using-joins-in-sql/</guid>
		<description><![CDATA[At work I always get confused on good practice of using joins&#8230; here is an example of a practical join. &#60;cfquery name=&#8220;getConcernDetails&#8221; datasource=&#8220;#someDSN#&#8221;&#62; SELECT C.concernID, C.ClientID, C.DateCreated, C.Status, C.ClientEmail, C.isConcern, C.ownerID, C.ownerGroupID, a.userID, a.username, s.label FROM unmc_Concerns C JOIN WLTAdminusers a ON c.ownerID = a.userid JOIN WLTsecurity s ON C.ownerGroupID = s.secid WHERE C.ConcernID = [...]]]></description>
			<content:encoded><![CDATA[<p class="body">At work I always get confused on good practice of using joins&#8230; here is an example of a practical join.</p>
<p class="code"><span style="color: #800000">&lt;cfquery name=<span style="color: #0000ff">&#8220;getConcernDetails&#8221;</span> datasource=<span style="color: #0000ff">&#8220;#someDSN#&#8221;</span>&gt;</span><br />
SELECT<br />
C.concernID, C.ClientID, C.DateCreated,<br />
C.Status, C.ClientEmail, C.isConcern,<br />
C.ownerID, C.ownerGroupID,<br />
a.userID, a.username, s.label</p>
<p>FROM<br />
unmc_Concerns C JOIN WLTAdminusers a ON c.ownerID = a.userid<br />
JOIN WLTsecurity s ON C.ownerGroupID = s.secid</p>
<p>WHERE<br />
C.ConcernID = <span style="color: #800000">&lt;cfqueryparam cfsqltype=<span style="color: #0000ff">&#8220;cf_sql_integer&#8221;</span> value=<span style="color: #0000ff">&#8220;#url.var_details#&#8221;</span> /&gt;</span><br />
ORDER BY<br />
C.ConcernID<br />
<span style="color: #800000">&lt;/cfquery&gt;</span></p>
<img src="http://www.axelscript.com/?ak_action=api_record_view&id=23&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.axelscript.com/2008/02/10/using-joins-in-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use of SQL GROUP BY</title>
		<link>http://www.axelscript.com/2008/02/10/use-of-sql-group-by/</link>
		<comments>http://www.axelscript.com/2008/02/10/use-of-sql-group-by/#comments</comments>
		<pubDate>Sun, 10 Feb 2008 18:55:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Coldfusion]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.axelscript.com/2008/02/10/use-of-sql-group-by/</guid>
		<description><![CDATA[I wrote this query for use on my site beta.killtheheart.com When you click on the hotlist tab you will see the query version 1: Problems&#8230; i was including the date in my query using a group by &#60;cfquery datasource=&#8220;#variables.dsn#&#8221; name=&#8220;qHotList&#8221;&#62; SELECT   l.artistID, l.AlbumID, l.Date, count(l.ArtistID) as recordCount, art.Artist, alb.Title FROM tblLogger l, tblArtists art, tblAlbums alb [...]]]></description>
			<content:encoded><![CDATA[<p class="body">I wrote this query for use on my site   <a href="http://www.beta.killtheheart.com">beta.killtheheart.com</a></p>
<p> When you click on the hotlist tab you will see the query</p>
<p>version 1: Problems&#8230; i was including the date in my query using a group by</p>
<p class="code"><span style="color: #800000">&lt;cfquery datasource=<span style="color: #0000ff">&#8220;#variables.dsn#&#8221;</span> name=<span style="color: #0000ff">&#8220;qHotList&#8221;</span>&gt;</span><br />
SELECT   l.artistID, l.AlbumID, l.Date, count(l.ArtistID) as recordCount, art.Artist, alb.Title<br />
FROM tblLogger l, tblArtists art, tblAlbums alb</p>
<p>WHERE l.ArtistID=art.ArtistID<br />
AND l.AlbumID=alb.AlbumID<br />
AND Date<br />
BETWEEN &#8217;10/15/06&#8242; and &#8217;10/18/06&#8242;</p>
<p>GROUP BY l.ArtistID,l.AlbumID, l.Date, art.Artist, alb.Title<br />
ORDER BY recordCount DESC<br />
<span style="color: #800000">&lt;/cfquery&gt;</span></p>
<p><span id="more-22"></span><br />
the result of this would be for instance<br />
==============================================<br />
Artist   &#8211;           Album<br />
#1.   311     &#8211;           Greatest Hits<br />
#2.   311     &#8211;           Greatest Hits<br />
#3.   311     &#8211;           Greatest Hits<br />
#4.   A.F.I   &#8211;           Decemberunderground<br />
#5.   A.F.I   &#8211;           Decemberunderground<br />
#6.   A.F.I   &#8211;           Decemberunderground<br />
==============================================<br />
I couldn&#8217;t understand why I was getting multiple rows? It was very confusing to me&#8230; I asked my boss who runs <a href="mkruger.cfwebtools.com">(Mark Kruger!)</a> and he informed me what was going on in the query and the reason i was getting multiple entries (1 for each day that had gone by) was because of my &#8220;date&#8221; column.</p>
<p>Here is version 2:</p>
<p class="code"><span style="color: #800000">&lt;cfquery datasource=<span style="color: #0000ff">&#8220;#variables.dsn#&#8221;</span> name=<span style="color: #0000ff">&#8220;qHotList&#8221;</span>&gt;</span><br />
SELECT   l.artistID, l.AlbumID, count(l.ArtistID) as recordCount, art.Artist, alb.Title<br />
FROM tblLogger l, tblArtists art, tblAlbums alb</p>
<p>WHERE l.ArtistID=art.ArtistID<br />
AND l.AlbumID=alb.AlbumID<br />
AND Date<br />
BETWEEN &#8217;10/15/06&#8242; and &#8217;10/18/06&#8242;</p>
<p>GROUP BY l.ArtistID,l.AlbumID, art.Artist, alb.Title<br />
ORDER BY recordCount DESC<br />
<span style="color: #800000">&lt;/cfquery&gt;</span></p>
<p>the result of this would be for instance<br />
==============================================<br />
Artist    &#8211;          Album<br />
#1.   311   &#8211;             Greatest Hits<br />
#2.   A.F.I   &#8211;           Decemberunderground<br />
==============================================<br />
And now the query works giving me a hot list of albums and artists that people have chosen on my site&#8230;</p>
<img src="http://www.axelscript.com/?ak_action=api_record_view&id=22&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.axelscript.com/2008/02/10/use-of-sql-group-by/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>using sub selects with SQL UPDATE</title>
		<link>http://www.axelscript.com/2008/02/09/using-sub-selects-with-sql-update/</link>
		<comments>http://www.axelscript.com/2008/02/09/using-sub-selects-with-sql-update/#comments</comments>
		<pubDate>Sat, 09 Feb 2008 20:03:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.axelscript.com/2008/02/09/using-sub-selects-with-sql-update/</guid>
		<description><![CDATA[Consider having the following tables. (Microsoft RMS) -Item -id -cost -SupplierList -itemID -supplierCost when using RMS, You have an Item, it has it&#8217;s own cost&#8230; maybe that cost is an average cost, or something like that, and that item may have multiple suppliers, and each supplier has an itemcost associated with it, this sucks with [...]]]></description>
			<content:encoded><![CDATA[<p>Consider having the following tables. (Microsoft RMS)  -Item<br />
-id<br />
-cost<br />
-SupplierList<br />
-itemID<br />
-supplierCost<br />
when using RMS, You have an Item, it has it&#8217;s own cost&#8230; maybe that cost is an average cost, or something like that, and that item may have multiple suppliers, and each supplier has an itemcost associated with it, this sucks with reporting and margins in RMS, because when you update the cost of the item, it doesnt update the supplier cost, because it doesnt know how to do so&#8230;</p>
<p><span id="more-10"></span><br />
<span id="more"></span></p>
<p class="code">UPDATE supplierlist<br />
SET cost =<br />
CASE<br />
WHEN (select id from item where id = itemid) = itemid<br />
THEN (select cost from item where id = itemid)<br />
else cost<br />
END</p>
<p>this query updates TWO tables from a base table&#8230; in our example it updates all of the suppliers cost, in the items table&#8230; it&#8217;s pretty cool</p>
<img src="http://www.axelscript.com/?ak_action=api_record_view&id=10&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.axelscript.com/2008/02/09/using-sub-selects-with-sql-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
