<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Channel 9 Forums - Tech Off - Should be simple SQL, but I&#39;m missing something</title>
	<atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Forums/rss"></atom:link>
	<image>
		<url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
		<title>Channel 9 Forums - Tech Off - Should be simple SQL, but I&#39;m missing something</title>
		<link>http://channel9.msdn.com/Forums</link>
	</image>
	<description>Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.</description>
	<link>http://channel9.msdn.com/Forums</link>
	<language>en</language>
	<pubDate>Sat, 25 May 2013 00:30:42 GMT</pubDate>
	<lastBuildDate>Sat, 25 May 2013 00:30:42 GMT</lastBuildDate>
	<generator>Rev9</generator>
	<c9:totalResults>2</c9:totalResults>
	<c9:pageCount>-2</c9:pageCount>
	<c9:pageSize>-1</c9:pageSize>
	<item>
		<title>Tech Off - Should be simple SQL, but I&#39;m missing something</title>
		<description><![CDATA[<p>We have two tables, Districts and DayAllotment<br />Districts is:<br />DistrictID int<br />Description varchar(25)<br /><br />DayAllotment is:<br />AllotmentID<br />DistrictID<br />DaysAllotted<br />HalfYear<br />Type<br />Year<br /><br />My Data in Day Allotment is something like this:<br />1&nbsp;&nbsp;&nbsp;&nbsp;1012&nbsp;&nbsp;&nbsp;&nbsp;23&nbsp;&nbsp;&nbsp;&nbsp;First&nbsp;&nbsp;&nbsp;&nbsp;Fish&nbsp;&nbsp;&nbsp;&nbsp;2008<br />2&nbsp;&nbsp;&nbsp;&nbsp;1012&nbsp;&nbsp;&nbsp;&nbsp;22&nbsp;&nbsp;&nbsp;&nbsp;Second&nbsp;&nbsp;&nbsp;&nbsp;Fish&nbsp;&nbsp;&nbsp;&nbsp;2008<br />3&nbsp;&nbsp;&nbsp;&nbsp;1012&nbsp;&nbsp;&nbsp;&nbsp;15&nbsp;&nbsp;&nbsp;&nbsp;First&nbsp;&nbsp;&nbsp;&nbsp;Boat&nbsp;&nbsp;&nbsp;&nbsp;2008<br />4&nbsp;&nbsp;&nbsp;&nbsp;1012&nbsp;&nbsp;&nbsp;&nbsp;14&nbsp;&nbsp;&nbsp;&nbsp;Second&nbsp;&nbsp;&nbsp;&nbsp;Boat&nbsp;&nbsp;&nbsp;&nbsp;2008<br />5&nbsp;&nbsp;&nbsp;&nbsp;2012&nbsp;&nbsp;&nbsp;&nbsp;23&nbsp;&nbsp;&nbsp;&nbsp;First&nbsp;&nbsp;&nbsp;&nbsp;Boat&nbsp;&nbsp;&nbsp;&nbsp;2008<br />6&nbsp;&nbsp;&nbsp;&nbsp;2012&nbsp;&nbsp;&nbsp;&nbsp;22&nbsp;&nbsp;&nbsp;&nbsp;Second&nbsp;&nbsp;&nbsp;&nbsp;Fish&nbsp;&nbsp;&nbsp;&nbsp;2008<br />7&nbsp;&nbsp;&nbsp;&nbsp;2012&nbsp;&nbsp;&nbsp;&nbsp;14&nbsp;&nbsp;&nbsp;&nbsp;Second&nbsp;&nbsp;&nbsp;&nbsp;Boat&nbsp;&nbsp;&nbsp;&nbsp;2008<br /><br />So, let's say I want a result set that looks for All Fish allotments for 2008. I want a result set that looks like this:<br />DistrictID&nbsp;&nbsp;&nbsp;&nbsp;First&nbsp;&nbsp;&nbsp;&nbsp;Second<br />1012&nbsp;&nbsp;&nbsp;&nbsp;23&nbsp;&nbsp;&nbsp;&nbsp;22<br />1013&nbsp;&nbsp;&nbsp;&nbsp;NULL&nbsp;&nbsp;&nbsp;&nbsp;22<br /><br /><br />I tried something like this:<br /><p>SELECT dist.DistrictID, fDays.DaysAllotted AS 'Jan.-Jun.', sDays.DaysAllotted AS 'Jul.-Dec.'<br />FROM dbo.law_Districts dist&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;LEFT JOIN law_DeputyDaysAllotment fDays ON dist.DistrictID = fDays.DistrictID<br />&nbsp;&nbsp;&nbsp;&nbsp;LEFT JOIN law_DeputyDaysAllotment sDays ON dist.DistrictID = sDays.DistrictID<br />WHERE ((fDays.HalfYearWindow = 'First' AND fDays.Year = @Year AND fDays.Type = @Type) OR (fDays.HalfYearWindow IS NULL))<br />&nbsp;&nbsp;&nbsp;&nbsp;OR ((sDays.HalfYearWindow = 'Second' AND sDays.Year = @Year AND sDays.Type = @Type) OR (sDays.HalfYearWindow IS NULL))ORDER BY dist.DistrictID</p>
But get the same results in both columns.<br /><br />I've tried some other ways of joining, but have gotten results where some districts were dropped. I won't always know which side will have the NULL values.<br /><br />I'm sure there are samples out there but I'm not sure what to search for. Would this be a cross join table?<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/448200-Should-be-simple-SQL-but-Im-missing-something/448200#448200</link>
		<pubDate>Fri, 12 Dec 2008 17:45:53 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/448200-Should-be-simple-SQL-but-Im-missing-something/448200#448200</guid>
		<dc:creator>qwert231</dc:creator>
		<slash:comments>2</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/qwert231/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Should be simple SQL, but I&#39;m missing something</title>
		<description><![CDATA[<p>Definitely not a cross join. You want a &quot;full outer join&quot; (includes rows from both tables even when they don't match). Here's the basic idea (minus the &quot;where&quot; clause):
<div><br /></div>
<blockquote class="webkit-indent-blockquote">SELECT<br />&nbsp;&nbsp; &nbsp;COALESCE(fDays.DistrictID, sDays.DistrictID) DistrictID<br />&nbsp;&nbsp; &nbsp;, fDays.DaysAllotted AS 'Jan.-Jun.'<br />&nbsp;&nbsp; &nbsp;, sDays.DaysAllotted AS 'Jul.-Dec.'<br />FROM<br />&nbsp;&nbsp; &nbsp;law_DeputyDaysAllotment fDays<br />&nbsp;&nbsp; &nbsp;FULL&nbsp;OUTER JOIN law_DeputyDaysAllotment sDays ON<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;fDays.DistrictID = sDays.DistrictID<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;AND fDays.Year = sDays.Year<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;AND fDays.Type = sDays.Type<br /></blockquote>
<div>
<div><br /></div>
<div>I did this by hand and didn't check it, so there may be one or two syntax errors lurking in there.</div>
</div></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/448200-Should-be-simple-SQL-but-Im-missing-something/aee5d7c0a02a4f4281399deb00026e06#aee5d7c0a02a4f4281399deb00026e06</link>
		<pubDate>Fri, 12 Dec 2008 22:08:44 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/448200-Should-be-simple-SQL-but-Im-missing-something/aee5d7c0a02a4f4281399deb00026e06#aee5d7c0a02a4f4281399deb00026e06</guid>
		<dc:creator>dpratt71</dc:creator>
		<slash:comments>2</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/dpratt71/Discussions/RSS</wfw:commentRss>
	</item>
</channel>
</rss>