<?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>Anthony DeBarros &#187; Programming</title>
	<atom:link href="http://www.anthonydebarros.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.anthonydebarros.com</link>
	<description>Data, journalism, code &#38; life</description>
	<lastBuildDate>Sat, 21 Aug 2010 22:05:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>WordPress: Separate Comments, Trackbacks</title>
		<link>http://www.anthonydebarros.com/2010/08/02/wordpress-tip-separating-comments-trackbacks/</link>
		<comments>http://www.anthonydebarros.com/2010/08/02/wordpress-tip-separating-comments-trackbacks/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 14:43:36 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.anthonydebarros.com/?p=891</guid>
		<description><![CDATA[I&#8217;ve been tinkering again with my site&#8217;s WordPress theme and wanted to address one of its weaknesses &#8212; the formatting of comments. In addition to adding Gravatars, I wanted to separate reader comments from automatically generated pingback/trackback posts. A quick Google search turned up just the tutorial I needed from the design blog Hongkiat.com: How to [...]]]></description>
			<content:encoded><![CDATA[<p><strong>I&#8217;ve been tinkering</strong> again with my site&#8217;s WordPress theme and wanted to address one of its weaknesses &#8212; the formatting of comments. In addition to adding <a href="http://en.gravatar.com/" target="_blank">Gravatars</a>, I wanted to separate reader comments from automatically generated pingback/trackback posts.</p>
<p>A quick Google search turned up just the tutorial I needed from the design blog <a href="http://www.hongkiat.com/blog/" target="_blank">Hongkiat.com</a>:</p>
<p><a href="http://www.hongkiat.com/blog/how-to-seperate-comments-and-trackbacks-wordpress-tips/">How to Separate Comments and Trackbacks [Wordpress Tips]</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anthonydebarros.com/2010/08/02/wordpress-tip-separating-comments-trackbacks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calculating Medians With SQL</title>
		<link>http://www.anthonydebarros.com/2010/07/25/calculating-medians-sql/</link>
		<comments>http://www.anthonydebarros.com/2010/07/25/calculating-medians-sql/#comments</comments>
		<pubDate>Sun, 25 Jul 2010 04:44:14 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.anthonydebarros.com/?p=823</guid>
		<description><![CDATA[Given that median is such a valuable statistical measure, it&#8217;s baffling that Microsoft&#8217;s SQL Server and other relational databases (MySQL, PostgreSQL) don&#8217;t have a built-in MEDIAN function. Well, this week, after working through a data set in SQL Server &#8212; and deciding I didn&#8217;t want to push the data into SPSS to find medians &#8212; [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Given that median</strong> is such a <a href="http://www.anthonydebarros.com/2009/12/27/mean-vs-median-excel/" target="_blank">valuable statistical measure</a>, it&#8217;s baffling that Microsoft&#8217;s SQL Server and other relational databases (MySQL, PostgreSQL) don&#8217;t have a built-in MEDIAN function. Well, this week, after working through a data set in SQL Server &#8212; and deciding I didn&#8217;t want to push the data into SPSS to find medians &#8212; I hit the web to find a T-SQL workaround.</p>
<p>I found a ton of solutions (some from people with no clue about the difference between <a href="http://www.anthonydebarros.com/2009/12/27/mean-vs-median-excel/">median and average</a>), but the one below &#8212; adapted from <a href="http://sqlblog.com/blogs/adam_machanic/archive/2006/12/18/medians-row-numbers-and-performance.aspx" target="_blank">a post by Adam Machanic at sqlblog.com</a> &#8212; was the best. It produces accurate results and is fairly speedy to boot.</p>
<p>Here&#8217;s an example. Consider this table with student grades from two courses:<br />
<code><span style="color: #ffffff;">.</span></code></p>
<table border="0">
<tbody>
<tr>
<th width="30px">ID</th>
<th width="90px">Class</th>
<th width="90px">FirstName</th>
<th>Grade</th>
</tr>
<tr>
<td>1</td>
<td>Math</td>
<td>Bob</td>
<td>65</td>
</tr>
<tr>
<td>2</td>
<td>Math</td>
<td>Joe</td>
<td>72</td>
</tr>
<tr>
<td>3</td>
<td>Math</td>
<td>Sally</td>
<td>95</td>
</tr>
<tr>
<td>4</td>
<td>Science</td>
<td>Bob</td>
<td>65</td>
</tr>
<tr>
<td>5</td>
<td>Science</td>
<td>Joe</td>
<td>81</td>
</tr>
<tr>
<td>6</td>
<td>Science</td>
<td>Sally</td>
<td>81</td>
</tr>
<tr>
<td>7</td>
<td>Science</td>
<td>Mike</td>
<td>72</td>
</tr>
</tbody>
</table>
<p>We&#8217;d like to find the median grade in each class. Here&#8217;s the script:<br />
<span id="more-823"></span><br />
<code><br />
DECLARE @tmp TABLE (<br />
&nbsp;&nbsp;&nbsp;ID int identity(1,1),<br />
&nbsp;&nbsp;&nbsp;Class varchar(50),<br />
&nbsp;&nbsp;&nbsp;FirstName varchar(50),<br />
&nbsp;&nbsp;&nbsp;Grade decimal(5,1)<br />
)</code></p>
<p><code> </code></p>
<p><code>INSERT INTO @tmp (Class, FirstName, Grade)<br />
&nbsp;&nbsp;&nbsp;VALUES ('Math', 'Bob', 65)<br />
INSERT INTO @tmp (Class, FirstName, Grade)<br />
&nbsp;&nbsp;&nbsp;VALUES ('Math', 'Joe', 72)<br />
INSERT INTO @tmp (Class, FirstName, Grade)<br />
&nbsp;&nbsp;&nbsp;VALUES ('Math', 'Sally', 95)<br />
INSERT INTO @tmp (Class, FirstName, Grade)<br />
&nbsp;&nbsp;&nbsp;VALUES ('Science', 'Bob', 65)<br />
INSERT INTO @tmp (Class, FirstName, Grade)<br />
&nbsp;&nbsp;&nbsp;VALUES ('Science', 'Joe', 81)<br />
INSERT INTO @tmp (Class, FirstName, Grade)<br />
&nbsp;&nbsp;&nbsp;VALUES ('Science', 'Sally', 81)<br />
INSERT INTO @tmp (Class, FirstName, Grade)<br />
&nbsp;&nbsp;&nbsp;VALUES ('Science', 'Mike', 72)</code></p>
<p><code> </code></p>
<p><code>SELECT<br />
&nbsp;&nbsp;&nbsp;x.Class,<br />
&nbsp;&nbsp;&nbsp;CAST(AVG(x.Grade) AS DECIMAL(6,1)) AS 'Median'<br />
FROM<br />
(<br />
&nbsp;&nbsp;&nbsp;SELECT<br />
&nbsp;&nbsp;&nbsp;Class,<br />
&nbsp;&nbsp;&nbsp;FirstName,<br />
&nbsp;&nbsp;&nbsp;Grade,<br />
&nbsp;&nbsp;&nbsp;ROW_NUMBER() OVER (<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PARTITION BY Class<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ORDER BY Grade ASC, ID ASC) AS RowAsc,<br />
&nbsp;&nbsp;&nbsp;ROW_NUMBER() OVER (<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PARTITION BY Class<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ORDER BY Grade DESC, ID DESC) AS RowDesc<br />
&nbsp;&nbsp;&nbsp;FROM @tmp<br />
) AS x<br />
WHERE<br />
&nbsp;&nbsp;&nbsp;RowAsc IN (RowDesc, RowDesc - 1, RowDesc + 1)<br />
GROUP BY x.Class<br />
ORDER BY x.Class<br />
</code><br />
That&#8217;s a lot. Let&#8217;s break down what&#8217;s happening.</p>
<p>First, to set up the data, we&#8217;re creating a temporary table and inserting seven rows.</p>
<p>Then comes the main SELECT, which includes a subquery that&#8217;s the meat of the goodness behind this. The subquery uses the <a href="http://msdn.microsoft.com/en-us/library/ms186734.aspx" target="_blank">ROW_NUMBER</a> function to create ascending and descending row identifiers based on the ordering of the grades. It&#8217;s easier to visualize if you see what the subquery&#8217;s creating:<br />
<code><span style="color: #ffffff;">.</span></code></p>
<table border="0">
<tbody>
<tr>
<th width="90px">Class</th>
<th width="90px">FirstName</th>
<th width="70px">Grade</th>
<th>RowAsc</th>
<th>RowDesc</th>
</tr>
<tr>
<td>Math</td>
<td>Sally</td>
<td>95.0</td>
<td>3</td>
<td>1</td>
</tr>
<tr>
<td>Math</td>
<td>Joe</td>
<td>72.0</td>
<td>2</td>
<td>2</td>
</tr>
<tr>
<td>Math</td>
<td>Bob</td>
<td>65.0</td>
<td>1</td>
<td>3</td>
</tr>
<tr>
<td>Science</td>
<td>Sally</td>
<td>81.0</td>
<td>4</td>
<td>1</td>
</tr>
<tr>
<td>Science</td>
<td>Joe</td>
<td>81.0</td>
<td>3</td>
<td>2</td>
</tr>
<tr>
<td>Science</td>
<td>Mike</td>
<td>72.0</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>Science</td>
<td>Bob</td>
<td>65.0</td>
<td>1</td>
<td>4</td>
</tr>
</tbody>
</table>
<p>The RowAsc and RowDesc fields reflect the ordered row numbers of the grades per each class (i.e., partition). Given those, it&#8217;s easy to find the median. For the math class, with an odd number of students, the median occurs where RowAsc equals RowDesc. For the science class, with an even number of students, the median is the average of the two grades where RowAsc and RowDesc are within one of each other.</p>
<p>(Whenever you&#8217;re looking for the median in an ordered list that has an even number of values, averaging the two middle numbers gives the answer.)</p>
<p>That&#8217;s what our main query does when it pulls from the subquery result set. It looks for:</p>
<p><code>RowAsc IN (RowDesc, RowDesc - 1, RowDesc + 1)</code></p>
<p>and then averages what it finds. The answer is 72 for the math class and 76.5 for science.</p>
<p>This solution works with T-SQL and Microsoft SQL Server. With minor tweaks, it also runs fine in PostgreSQL 8.4, which also implements the ROW_NUMBER function. MySQL does not support that function, so you&#8217;ll have to search for another option. </p>
<p>Good stuff and pretty handy for extracting large numbers of median values without having to resort to a stats program.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anthonydebarros.com/2010/07/25/calculating-medians-sql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Download My WordPress Theme</title>
		<link>http://www.anthonydebarros.com/2010/06/19/download-wordpress-theme/</link>
		<comments>http://www.anthonydebarros.com/2010/06/19/download-wordpress-theme/#comments</comments>
		<pubDate>Sat, 19 Jun 2010 21:29:36 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.anthonydebarros.com/?p=345</guid>
		<description><![CDATA[I make no claim to having any design sense, but if you like my site&#8217;s WordPress theme, you&#8217;re welcome to it. Grab it right here. Portfolio AD is a one-column theme with a two-column sidebar. Both columns in the sidebar can display widgets. The header is a modification of the well-worn Hemingway theme, and the [...]]]></description>
			<content:encoded><![CDATA[<p><strong>I make no claim </strong>to having any design sense, but if you like my site&#8217;s WordPress theme, you&#8217;re welcome to it. Grab it <a href="http://www.anthonydebarros.com/wp-content/themes/portfolio_ad/docs/portfolio_ad.zip" target="_blank">right here</a>.</p>
<p>Portfolio AD is a one-column theme with a two-column sidebar. Both  columns in the sidebar can display widgets. The header is a modification  of the well-worn <a href="http://warpspire.com/hemingway/" target="_blank">Hemingway</a> theme, and the rest is my take-off of a site built via <a href="http://www.wpdesigner.com/2007/02/19/so-you-want-to-create-wordpress-themes-huh/" target="_blank">this tutorial</a> from <a href="http://www.wpdesigner.com/" target="_blank">WPDesigner.com</a>. It works fine with WordPress 3.0.</p>
<p>What you see here is the result of <a href="http://twitter.com/AnthonyDB/status/7560546852" target="_blank">constant tinkering</a>. I coded up a theme of my own to learn more about what WordPress can do, and in the process I have learned tons about CSS, HTML, web hosting and content management systems in general. If you have the time, it&#8217;s well worth the investment.</p>
<p>Use the theme as a starting point for your own tinkering and have fun!</p>
<p><a href="http://www.anthonydebarros.com/wp-content/themes/portfolio_ad/docs/portfolio_ad.zip"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.anthonydebarros.com/2010/06/19/download-wordpress-theme/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>You Can&#8217;t Afford to Stop Learning</title>
		<link>http://www.anthonydebarros.com/2010/04/02/you-cant-stop-learning/</link>
		<comments>http://www.anthonydebarros.com/2010/04/02/you-cant-stop-learning/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 15:55:54 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Life]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.anthonydebarros.com/?p=476</guid>
		<description><![CDATA[The late Jerry McBride, founder of the Marist College information systems program and mentor to many of us in it, gave our capstone class a bit of advice that I&#8217;ve always remembered: &#8220;Never stop learning.&#8221; Plenty of people, regardless of industry, argue otherwise. Play it safe, take few risks and stay with the tried and [...]]]></description>
			<content:encoded><![CDATA[<p><strong>The late <a href="http://www.nyjnews.com/obituary/obit.php3?id=2124485" target="_blank">Jerry McBride</a>,</strong> founder of the <a href="http://www.marist.edu/" target="_blank">Marist College</a> information systems program and mentor to many of us in it, gave our capstone class a bit of advice that I&#8217;ve always remembered:</p>
<p>&#8220;Never stop learning.&#8221;</p>
<p>Plenty of people, regardless of industry, argue otherwise. Play it safe, take few risks and stay with the tried and true &#8212; that keeps the bills paid and the lights on.</p>
<p>Decades ago, &#8220;No one ever got fired for buying IBM&#8221; was a phrase you could bank on. IBM had it all &#8212; the kings of the <a href="http://www-03.ibm.com/ibm/history/exhibits/mainframe/mainframe_PP9000.html" target="_blank">air-conditioned mainframe</a>, making oodles of money, and very snug in their white-shirt-and-tie ways. But they were slow to learn. PCs came along, the <a href="http://www.nytimes.com/1992/01/18/business/ibm-loss-in-quarter-and-year.html?pagewanted=1" target="_blank">mainframe business withered</a>, <a href="http://www-01.ibm.com/software/os/warp-withdrawal/" target="_blank">OS/2 failed to unseat Windows</a>, and tens of thousands of people in IBM-hometowns found themselves <a href="http://www.poughkeepsiejournal.com/article/20090127/BUSINESS01/90127016/IBM-East-Fishkill-over-the-years" target="_blank">unemployed</a>. IBM&#8217;s come back, but it&#8217;s nothing like the company it was in 1980.</p>
<p>Stop learning, rest on the existing models, and it&#8217;s easy to become a mainframe-hawker in a PC revolution. Or a railroad tycoon watching with disregard as Henry Ford mass produces Model T&#8217;s.</p>
<p>I&#8217;ve practiced Jerry McBride&#8217;s advice better at times than others. Lately, very much so. I&#8217;m on a learning jag. My latest quest is Ubuntu, Apache, PostgreSQL and Django. Last night, this little screen brought a smile or two:</p>
<p><a href="http://www.anthonydebarros.com/wp-content/uploads/2010/04/Screenshot.png"><img class="alignnone size-full wp-image-477" style="border: 0pt none;" title="Screenshot" src="http://www.anthonydebarros.com/wp-content/uploads/2010/04/Screenshot.png" alt="" width="448" height="319" /></a></p>
<p>P.S. My bookmarks and RSS feeds prove one thing: There&#8217;s no excuse for not learning; the Internet is the best free library you&#8217;ll ever find.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anthonydebarros.com/2010/04/02/you-cant-stop-learning/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Essential SQL Queries (To Me, At Least)</title>
		<link>http://www.anthonydebarros.com/2010/03/11/essential-sql-queries/</link>
		<comments>http://www.anthonydebarros.com/2010/03/11/essential-sql-queries/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 20:44:05 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.anthonydebarros.com/?p=428</guid>
		<description><![CDATA[For a session of five-minute &#8220;lightning talks&#8221; at this week&#8217;s 2010 Investigative Reporters and Editors conference in Phoenix, I contributed &#8220;Five Essential Queries for SQL Server.&#8221; Aside from the basic SELECT statement, these are five techniques that, at least for me, either solved a tricky problem or made coding life more efficient. They came to [...]]]></description>
			<content:encoded><![CDATA[<p><strong>For a session of</strong> five-minute <a href="http://en.wikipedia.org/wiki/Lightning_Talk" target="_blank">&#8220;lightning talks&#8221;</a> at this week&#8217;s 2010 Investigative Reporters and Editors conference in Phoenix, I contributed &#8220;Five Essential Queries for SQL Server.&#8221; Aside from the basic SELECT statement, these are five techniques that, at least for me, either solved a tricky problem or made coding life more efficient. They came to me after some trial and error or from using the coder&#8217;s best friend, Google.</p>
<p>I realize that many journalists prefer the open source (free) MySQL to Microsoft&#8217;s product, so I&#8217;ve replicated the five queries below in MySQL syntax. You can download script files for either syntax here:</p>
<p>&#8211; <a href="http://www.anthonydebarros.com/wp-content/themes/portfolio_ad/docs/FiveEssentialSQLQueries_SQLServer.sql" target="_blank">Five essential queries (MS SQL Server)</a><br />
&#8211; <a href="http://www.anthonydebarros.com/wp-content/themes/portfolio_ad/docs/FiveEssentialSQLQueries_MySQL.sql" target="_blank">Five essential queries (MySQL)</a></p>
<p>Feedback and your ideas are welcome. Here they are:</p>
<p><strong>1. Create a temporary table with identity column.</strong><br />
Temp tables are handy for storing and manipulating data when you need a table but don&#8217;t want to make it part of your actual schema. In SQL Server, the table variable is held in memory and disappears once the query finishes executing.</p>
<p><code>DECLARE @tmp TABLE (<br />
&nbsp;&nbsp;&nbsp;id int identity(1,1),<br />
&nbsp;&nbsp;&nbsp;FirstName varchar(50))</code></p>
<p><code>INSERT INTO @tmp (FirstName) VALUES ('Bob')</code><br />
<code>INSERT INTO @tmp (FirstName) VALUES ('Joe')</code><br />
<code>INSERT INTO @tmp (FirstName) VALUES ('Sally')</code></p>
<p><code>SELECT * FROM @tmp</code><br />
<span id="more-428"></span><br />
<strong>2. Use a CASE expression to update a field based on values in another field.</strong><br />
Here, we create a temporary table that has FirstName and NickName fields. If we want to update the NickName field based on the values found in FirstName, we can use a standard UPDATE statement with CASE embedded.</p>
<p><code>DECLARE @tmp TABLE (</code><br />
&nbsp;&nbsp;&nbsp;<code> id int identity(1,1),</code><br />
&nbsp;&nbsp;&nbsp;<code> FirstName varchar(50),</code><br />
&nbsp;&nbsp;&nbsp;<code> NickName varchar(50))</code></p>
<p><code>INSERT INTO @tmp (FirstName) VALUES ('Robert')</code><br />
<code>INSERT INTO @tmp (FirstName) VALUES ('Joseph')</code><br />
<code>INSERT INTO @tmp (FirstName) VALUES ('Elizabeth')</code></p>
<p><code>UPDATE @tmp</code><br />
<code>SET Nickname =</code><br />
&nbsp;&nbsp;&nbsp;<code>CASE</code><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<code>WHEN FirstName = 'Robert' THEN 'Bob'</code><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<code>WHEN FirstName = 'Joseph' THEN 'Joe'</code><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<code>WHEN FirstName = 'Elizabeth' THEN 'Liz'</code><br />
&nbsp;&nbsp;&nbsp;<code>END</code></p>
<p><code>SELECT * FROM @tmp</code></p>
<p><strong>3. Join a table to itself using aliasing.</strong><br />
Sometimes, it&#8217;s handy to be able to join a table to itself or to join the results of two or more queries. Using aliases is a helpful way to do this. In this example, we create a table to hold information on eating contests. Each row has the result for one contestant and includes name, contest date and their result.</p>
<p>Let&#8217;s say we want to know, for each contestant, their most recent contest and how well they did. First we need to find the maximum date for their name and then find the result on that date. We do both operations as separate queries and assign each an alias &#8212; in this case, A and B. We can then join those to query them as if they were two separate tables.<br />
<code><br />
DECLARE @EatingContests TABLE (</code><br />
&nbsp;&nbsp;&nbsp;<code>id int identity(1,1),</code><br />
&nbsp;&nbsp;&nbsp;<code>FirstName varchar(50),</code><br />
&nbsp;&nbsp;&nbsp;<code>cDate datetime,</code><br />
&nbsp;&nbsp;&nbsp;<code>Result int)</code><br />
<code><br />
INSERT INTO @EatingContests (FirstName, cDate, Result) VALUES ('Bill','3/2/2010','4')</code><br />
<code>INSERT INTO @EatingContests (FirstName, cDate, Result) VALUES ('Bill','5/18/2010','3')</code><br />
<code>INSERT INTO @EatingContests (FirstName, cDate, Result) VALUES ('Bill','12/19/2010','1')</code><br />
<code>INSERT INTO @EatingContests (FirstName, cDate, Result) VALUES ('Lisa','3/2/2010','6')</code><br />
<code>INSERT INTO @EatingContests (FirstName, cDate, Result) VALUES ('Lisa','12/7/2009','1')</code><br />
<code>INSERT INTO @EatingContests (FirstName, cDate, Result) VALUES ('Lisa','1/6/2010','2')</code><br />
<code>INSERT INTO @EatingContests (FirstName, cDate, Result) VALUES ('Lou','3/2/2010','3')</code><br />
<code>INSERT INTO @EatingContests (FirstName, cDate, Result) VALUES ('Lou','4/4/2010','5')</code><br />
<code>INSERT INTO @EatingContests (FirstName, cDate, Result) VALUES ('Lou','9/16/2009','1')</code></p>
<p><code>SELECT A.FirstName, A.MaxDate, B.Result<br />
FROM<br />
&nbsp;&nbsp;&nbsp;(SELECT FirstName, Max(cDate) AS 'MaxDate'<br />
&nbsp;&nbsp;&nbsp;FROM @EatingContests<br />
&nbsp;&nbsp;&nbsp;GROUP BY FirstName)<br />
&nbsp;&nbsp;&nbsp;AS A<br />
LEFT JOIN<br />
&nbsp;&nbsp;&nbsp;(SELECT FirstName, cDate, Result<br />
&nbsp;&nbsp;&nbsp;FROM @EatingContests)<br />
&nbsp;&nbsp;&nbsp;AS B<br />
ON A.FirstName = B.FirstName AND A.MaxDate = B.cDate</code></p>
<p><strong>4. Rank query results.</strong><br />
SQL Server has a very handy RANK function that will return the rank of a value we specify in the query.<br />
Here we have a table of names and salaries. We use RANK to order the names by salary and provide the rank. Note that RANK shows that two people tied for 2nd and then ranks the next person 4th.</p>
<p><code>DECLARE @tmp TABLE (<br />
&nbsp;&nbsp;&nbsp;id int identity(1,1),<br />
&nbsp;&nbsp;&nbsp;FirstName varchar(50),<br />
&nbsp;&nbsp;&nbsp;Salary int)<br />
</code><br />
<code>INSERT INTO @tmp (FirstName, Salary) VALUES ('Robert','25000')<br />
INSERT INTO @tmp (FirstName, Salary) VALUES ('Jan','36000')<br />
INSERT INTO @tmp (FirstName, Salary) VALUES ('Mike','48000')<br />
INSERT INTO @tmp (FirstName, Salary) VALUES ('Sarah','51000')<br />
INSERT INTO @tmp (FirstName, Salary) VALUES ('Lisa','48000')<br />
INSERT INTO @tmp (FirstName, Salary) VALUES ('Steve','22000')<br />
</code><br />
<code>SELECT FirstName, Salary, RANK() OVER (ORDER BY Salary DESC) AS 'Rank'<br />
FROM @tmp</code></p>
<p><strong>5. Concatenate row values into one field</strong><br />
The table created with the script below has names and test scores. For some applications, it&#8217;s handy to present these values in a list, such as &#8220;82, 93, 74&#8243;.</p>
<p>MySQL&#8217;s GROUP_CONCAT function does this easily, but there&#8217;s no similar option in SQL Server. It can be done, though, and this syntax (which I stumbled upon after an eternity of Googling), makes use of both the STUFF function and the FOR XML PATH output option. STUFF inserts text inside another piece of text.</p>
<p><code>CREATE TABLE #tmp (<br />
&nbsp;&nbsp;&nbsp;id int identity(1,1),<br />
&nbsp;&nbsp;&nbsp;FirstName varchar(50),<br />
&nbsp;&nbsp;&nbsp;Score varchar(10))<br />
</code><br />
<code>INSERT INTO #tmp (FirstName, Score) VALUES ('Dana','82');<br />
INSERT INTO #tmp (FirstName, Score) VALUES ('Dana','93');<br />
INSERT INTO #tmp (FirstName, Score) VALUES ('Dana','74');<br />
INSERT INTO #tmp (FirstName, Score) VALUES ('Tammy','92');<br />
INSERT INTO #tmp (FirstName, Score) VALUES ('Tammy','98');</code></p>
<p><code>SELECT<br />
FirstName,<br />
&nbsp;&nbsp;&nbsp;STUFF((<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SELECT ', ' + t.Score<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FROM #tmp t<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WHERE t.FirstName = #tmp.FirstName<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ORDER BY t.Score DESC<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FOR XML PATH('')<br />
&nbsp;&nbsp;&nbsp;),1,1,'') as Scores<br />
FROM #tmp<br />
GROUP BY FirstName</code></p>
<p><code>DROP TABLE #tmp</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.anthonydebarros.com/2010/03/11/essential-sql-queries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Take my WordPress theme, please</title>
		<link>http://www.anthonydebarros.com/2009/11/23/take-my-wordpress-theme-please/</link>
		<comments>http://www.anthonydebarros.com/2009/11/23/take-my-wordpress-theme-please/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 23:07:08 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.anthonydebarros.com/?p=233</guid>
		<description><![CDATA[Building a WordPress theme from scratch has been a blast. Not only did I pick up new skills in CSS and PHP, I developed a deeper appreciation for the open source community. Without dozens of people who liberally share their code, I wouldn&#8217;t have gotten as far as fast. So, I&#8217;d like to return the [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Building a WordPress theme</strong> from scratch has been a blast. Not only did I pick up new skills in CSS and PHP, I developed a deeper appreciation for the open source community. Without dozens of people who liberally share their code, I wouldn&#8217;t have gotten as far as fast.</p>
<p>So, I&#8217;d like to return the favor. Anyone who&#8217;d like my WordPress theme can have it. I have no illusions about being a designer, but if you&#8217;re looking to craft your own theme it&#8217;s a good start.</p>
<p><a href="http://www.anthonydebarros.com/wp-content/themes/portfolio_ad/docs/portfolio_ad.zip">Download Portfolio_AD here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anthonydebarros.com/2009/11/23/take-my-wordpress-theme-please/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Variations on a WordPress theme</title>
		<link>http://www.anthonydebarros.com/2009/08/30/variations-on-a-theme/</link>
		<comments>http://www.anthonydebarros.com/2009/08/30/variations-on-a-theme/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 02:21:46 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.anthonydebarros.com/?p=21</guid>
		<description><![CDATA[After working through a tutorial on building WordPress themes by wpdesigner.com, I had a basic, functional &#8212; and clunky looking &#8212; theme for my site. It had all the elements that I now understand to be the WordPress basics &#8212; a header, a content well for posts, a sidebar for links, pages and archives, plus a [...]]]></description>
			<content:encoded><![CDATA[<p><strong>After working through</strong> a <a href="http://www.wpdesigner.com/2007/02/19/so-you-want-to-create-wordpress-themes-huh/" target="_blank">tutorial</a> on building WordPress themes by <a href="http://www.wpdesigner.com/" target="_blank">wpdesigner.com</a>, I had a basic, functional &#8212; and clunky looking &#8212; theme for my site. It had all the elements that I now understand to be the WordPress basics &#8212; a header, a content well for posts, a sidebar for links, pages and archives, plus a footer.</p>
<p>Everything worked, but it had no style.</p>
<p>Of course, the reason I set out to build a theme from scratch was to make something unique. I&#8217;ve been impressed, for example, at what the author of <a href="http://flowingdata.com/" target="_blank">FlowingData</a> has achieved using WordPress. And I like a good challenge.</p>
<p>So, I&#8217;ve spent the last few days digging into my CSS. I&#8217;ve used style sheets at work for internal projects I code in Visual Studio, so I have a head start. A reference <a href="http://www.w3schools.com/Css/default.asp" target="_blank">CSS tutorial</a> is handy for defining various elements, but I probably am learning the most by studying (and borrowing from) a couple of themes I&#8217;ve admired: <a href="http://warpspire.com/hemingway/" target="_blank">Hemingway</a> and <a href="http://graphpaperpress.com/2008/02/06/monochrome-lite/" target="_blank">Monochrome Lite</a>.</p>
<p>If you know the Hemingway theme well, you&#8217;ll recognize shades of it in my  current header, which closely resembles the Hemingway header. I added a horizontal navigation bar that separates the top from the content to come. I&#8217;ve yet to style the content well, but I did decide to create left, middle and right divs for blocks of content. More to come &#8212; and I definitely will have to ask for help with colors. It&#8217;s what I know the least about.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anthonydebarros.com/2009/08/30/variations-on-a-theme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress from the inside out</title>
		<link>http://www.anthonydebarros.com/2009/08/24/learning-from-the-inside-out/</link>
		<comments>http://www.anthonydebarros.com/2009/08/24/learning-from-the-inside-out/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 04:01:28 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.anthonydebarros.com/?p=16</guid>
		<description><![CDATA[After searching the Web for the right WordPress theme for my site, I realized that none fit what I wanted. Hemingway, which I discovered through Derek Willis&#8217; site Fumblerooski, has the right vibe, but the layout is all wrong. So, I decided to learn how to build one from scratch. What you see now (or, [...]]]></description>
			<content:encoded><![CDATA[<p>After searching the Web for the right WordPress theme for my site, I realized that none fit what I wanted. <a href="http://warpspire.com/hemingway/" target="_blank">Hemingway</a>, which I discovered through Derek Willis&#8217; site <a href="http://www.fumblerooski.org/" target="_blank">Fumblerooski</a>, has the right vibe, but the layout is all wrong. So, I decided to learn how to build one from scratch.</p>
<p>What you see now (or, what you would have seen if you were here now), is the result of studiously following this <a href="http://www.wpdesigner.com/2007/02/19/so-you-want-to-create-wordpress-themes-huh/" target="_blank">detailed tutorial</a>. I&#8217;m glad I slogged through it, because it largely demystified WordPress. The process gave me the same feeling I had when, as a geeky 12-year-old, I took apart my family&#8217;s lawnmower engine. Seeing the parts moving on the inside really helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anthonydebarros.com/2009/08/24/learning-from-the-inside-out/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
