<?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>super-cooper &#187; sql</title>
	<atom:link href="http://www.super-cooper.com/archive/tag/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.super-cooper.com</link>
	<description>Python, GIS, and a sprinkling of mindless drivel from Chad Cooper</description>
	<lastBuildDate>Sat, 21 Aug 2010 20:22:37 +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>Concatenation and logic in SQL calls</title>
		<link>http://www.super-cooper.com/archive/2005/08/18/concatenation-and-logic-in-sql-calls/</link>
		<comments>http://www.super-cooper.com/archive/2005/08/18/concatenation-and-logic-in-sql-calls/#comments</comments>
		<pubDate>Fri, 19 Aug 2005 01:05:43 +0000</pubDate>
		<dc:creator>Chad</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://super-cooper.com/?p=95</guid>
		<description><![CDATA[I&#8217;ve been doing alot of database design lately, although nothing too fancy, just some personal Access databases. However, I have run across some cool stuff that really got me excited (as pathetic as that may seem): concatenating fields and using logic in SQL calls. The only thing that aggravates me is that I&#8217;ve went this [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been doing alot of database design lately, although nothing too fancy, just some personal Access databases. However, I have run across some cool stuff that really got me excited (as pathetic as that may seem): concatenating fields and using logic in SQL calls. The only thing that aggravates me is that I&#8217;ve went this long without knowing of these little jewels. The concatenation is pretty straightforward; take field A and concatenate field B to it, then alias it as field C, like so:</p>
<p><code>SELECT tableA.fieldA &#038; " " &#038; tableB.fieldB AS fieldC</code></p>
<p>which gives you the data in fieldA concatenated to  fieldB, separated by a space, as field C.</p>
<p>The logic is even better. I was importing the data from Access to Excel, so I could insert the Excel sheets into a map, all prettied up with lots of formatting. It worked great, except one field in my database contains null values, and when I imported that field from Access, Excel put zeros in place of the null values. This was unacceptable. So I figured that with the <code><a href="http://sqlzoo.net/howto/source/z.dir/tip667449/access">IIf</a></code> function in my SQL call, I could get only the records from the field that were not null. Problem solved. In the end, the call looked something like this:</p>
<p><code>SELECT tblWell.Well_Name &#038; ' ' &#038; tblWell.Well_No AS ShortWellName, tblWell.SpudDate, tblWell.Status, tblCompletion.Frac, tblGeology.RHOB_Pay_T, tblGeology.Shale_Thick, tblProduction.Online_Date, IIf(tblProduction.Rate<>' ',tblProduction.Rate &#038; " on " &#038; (Format(tblProduction.Rate_Date,"m/d/yyyy"))) AS CurrProd<br />
FROM (((tblWell LEFT JOIN tblCompletion ON tblWell.ID = tblCompletion.ID) LEFT JOIN tblGeology ON tblWell.ID = tblGeology.ID) INNER JOIN tblProduction ON tblWell.ID = tblProduction.ID) INNER JOIN tblFieldNames ON tblWell.FieldNo = tblFieldNames.ID<br />
WHERE (((twlWell.Status)<>'Proposed')) AND (((tblFieldNames.FieldName)='Whatever Field'))<br />
ORDER BY SpudDate ASC;</code></p>
<p>Whew.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.super-cooper.com/archive/2005/08/18/concatenation-and-logic-in-sql-calls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
