<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Defaulting Null values in SQL*Loader</title>
	<atom:link href="http://mikesmithers.wordpress.com/2012/12/27/defaulting-null-values-in-sqlloader/feed/" rel="self" type="application/rss+xml" />
	<link>http://mikesmithers.wordpress.com/2012/12/27/defaulting-null-values-in-sqlloader/</link>
	<description>Oracle - for when it was like that when you got there</description>
	<lastBuildDate>Wed, 01 May 2013 11:15:26 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Richard Willatt</title>
		<link>http://mikesmithers.wordpress.com/2012/12/27/defaulting-null-values-in-sqlloader/#comment-40147</link>
		<dc:creator><![CDATA[Richard Willatt]]></dc:creator>
		<pubDate>Thu, 25 Apr 2013 13:44:44 +0000</pubDate>
		<guid isPermaLink="false">http://mikesmithers.wordpress.com/?p=1727#comment-40147</guid>
		<description><![CDATA[Mike, 

  

First, apologies for not responding sooner!  It has been a busy week and I’m only now getting to my “weekend job” as volunteer webmaster &amp; database manager for our local youth rugby football league. 

  

BTW - I’m using MS SQL 2012 managed through MS Visual Studio 2012. 

  

Many thanks for the suggested schema.  At first reading, it looks like just what I need. I plan to take a crack this weekend at adapting your scripts to my existing schema. I’ll let you know how I get on. 

  

One observation from a NON-expert when it comes to relational databases.  Local, volunteer run, sports leagues, whether rugby, soccer, or whatever sport you like, are ubiquitous around the world.  I did a fair bit of research online looking for a SQL script that basically amounted to a cheat sheet on how to set up tables/views and queries for a rugby football Results table and a Standings table – such as the topic of this thread.  I could not find anything that I could easily adapt for the Standings.  I am, in fact, quite surprised that some sports mad academic in the IT department at some university somewhere has not published online a set of “sports league” scripts for use by volunteers &amp; amateurs like me.  

  

Anyhow, many thanks for the help &amp; advice! 

  

Cheers, 

  

Richard.]]></description>
		<content:encoded><![CDATA[<p>Mike, </p>
<p>First, apologies for not responding sooner!  It has been a busy week and I’m only now getting to my “weekend job” as volunteer webmaster &amp; database manager for our local youth rugby football league. </p>
<p>BTW &#8211; I’m using MS SQL 2012 managed through MS Visual Studio 2012. </p>
<p>Many thanks for the suggested schema.  At first reading, it looks like just what I need. I plan to take a crack this weekend at adapting your scripts to my existing schema. I’ll let you know how I get on. </p>
<p>One observation from a NON-expert when it comes to relational databases.  Local, volunteer run, sports leagues, whether rugby, soccer, or whatever sport you like, are ubiquitous around the world.  I did a fair bit of research online looking for a SQL script that basically amounted to a cheat sheet on how to set up tables/views and queries for a rugby football Results table and a Standings table – such as the topic of this thread.  I could not find anything that I could easily adapt for the Standings.  I am, in fact, quite surprised that some sports mad academic in the IT department at some university somewhere has not published online a set of “sports league” scripts for use by volunteers &amp; amateurs like me.  </p>
<p>Anyhow, many thanks for the help &amp; advice! </p>
<p>Cheers, </p>
<p>Richard.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mikesmithers</title>
		<link>http://mikesmithers.wordpress.com/2012/12/27/defaulting-null-values-in-sqlloader/#comment-39799</link>
		<dc:creator><![CDATA[mikesmithers]]></dc:creator>
		<pubDate>Mon, 22 Apr 2013 21:38:14 +0000</pubDate>
		<guid isPermaLink="false">http://mikesmithers.wordpress.com/?p=1727#comment-39799</guid>
		<description><![CDATA[Richard,

I&#039;m assuming that you&#039;re using Oracle or some other relational database ( and not one of those new-fangled No-SQL ones). I&#039;m also assuming that points are awarded as follows :

a win is 4 points
a draw is 2 points
a bonus point for scoring 4 or more tries in a game (win or lose)
a bonus point for losing by 7 points or less


So...you don&#039;t get another bonus point for 8 tries in a game. Also, you can get up to 2 bonus points if you lose the game, but only one at best, if you win.

I&#039;ve created a simplified results table. It&#039;s probably not the way you&#039;ve implemented it, but it makes this example a bit simpler.

[sourcecode wraplines=&quot;false&quot; language=&quot;sql&quot;]
CREATE TABLE team_results(
    team_name VARCHAR2(30),
    opposition VARCHAR2(30),
    points_for NUMBER(3),
    tries NUMBER(2),
    points_ag NUMBER(3))
/

--
-- Now for some test data...
--
INSERT INTO team_results(
    team_name, opposition,
    points_for, tries, points_ag)
VALUES(
    &#039;WALES&#039;, &#039;AUSTRALIA&#039;,
    12, 0 , 14)
/

INSERT INTO team_results(
   team_name, opposition,
   points_for, tries, points_ag)
VALUES(
    &#039;WALES&#039;, &#039;NEW ZEALAND&#039;,
    12,1,33)
/

INSERT INTO team_results(
    team_name, opposition,
    points_for, tries, points_ag) 
VALUES(
    &#039;WALES&#039;, &#039;FRANCE&#039;,
    26,1,17)
/

--
-- Unlike Wales, South Africa have scored four or more tries in a game th‎is season...
-- as well as having a draw...
--

INSERT INTO team_results(
    team_name, opposition,
    points_for, tries, points_ag) 
VALUES( &#039;SOUTH AFRICA&#039;, &#039;AUSTRALIA&#039;,
    31,5,9)
/

INSERT INTO team_results(
    team_name, opposition,
    points_for, tries, points_ag) 
VALUES(
    &#039;SOUTH AFRICA&#039;, &#039;AUSTRALIA&#039;,
    19,2,26)
/

INSERT INTO team_results(
    team_name, opposition,
    points_for, tries, points_ag) 
VALUES(
    &#039;SOUTH AFRICA&#039;, &#039;ENGLAND&#039;,
    14,1,14)
/

COMMIT;

[/sourcecode]

So, if we look at the results:

[sourcecode wraplines=&quot;false&quot; language=&quot;sql&quot;]
SELECT team_name, points_for, points_ag, tries 
FROM team_results
ORDER BY team_name
/

TEAM_NAME		       POINTS_FOR  POINTS_AG	  TRIES
------------------------------ ---------- ---------- ----------
SOUTH AFRICA			       19	  26	      2
SOUTH AFRICA			       31	   9	      5
SOUTH AFRICA			       14	  14	      1
WALES				       12	  33	      1
WALES				       12	  14	      0
WALES				       26	  17	      1

6 rows selected.

SQL&gt;
[/sourcecode]


... for Wales, we can see that they&#039;ll get One point for the loss to Australia ( less than 7 point margin), nothing from their defeat to New Zealand, and four points from their win over France.
This makes a total of 5 points, including 1 bonus points.

As for South Africa, they&#039;ll get five points from their win over Australia ( 4 plus a bonus point for tries scored),
One for their defeat to Australia ( 7 points or less)
And two points from their draw against England.
This give them a total of 8 points (including 2 bonus points).
       
To derive this from the raw data, we can use the CASE statement in our query.
We&#039;re also using an in-line view to tidy up the calculation of overall points

[sourcecode highlight=&quot;12,13,14,15,17,18,19,20&quot; language=&quot;sql&quot;]
SELECT team_name, pld, bp, bp+points as total_points
FROM (
    SELECT team_name,
        COUNT(team_name) as pld,
        SUM(
            CASE 
                WHEN points_for &gt; points_ag THEN 4
                WHEN points_for = points_ag THEN 2
                ELSE 0
           END) as points,
        SUM(
            CASE
                WHEN tries &gt;= 4 THEN 1
                ELSE 0
           END) +
        SUM(
            CASE
                WHEN points_ag &gt; points_for AND points_for + 7 &gt;= points_ag THEN 1
                ELSE 0
            END) as bp
    FROM team_results
    GROUP BY team_name)
/

[/sourcecode]

Run this and we get :

[sourcecode wraplines=&quot;false&quot; language=&quot;sql&quot;]
TEAM_NAME			      PLD	  BP TOTAL_POINTS
------------------------------ ---------- ---------- ------------
SOUTH AFRICA				3	   2		8
WALES					3	   1		5

SQL&gt; 
[/sourcecode] 

I think the short answer to your question about bonus point calculation is to
use the CASE statement, which as you can see, can handle compound conditions
(lost, but by 7 points or less).

There are a couple of posts which may be of interest ( although they&#039;re based
on the round-ball game, rather than the oval one).
&lt;a href=&quot;http://wp.me/pweWl-fu&quot; rel=&quot;nofollow&quot;&gt;This post&lt;/a&gt; outlines some possibilities when designing the database.
&lt;a href=&quot;http://wp.me/pweWl-f4&quot; rel=&quot;nofollow&quot;&gt;This one&lt;/a&gt; makes use of Oracle&#039;s RANK function so that you can order your result
set by multiple criteria easily.

HTH

Mike

P.S. Sorry some of the formatting is a bit wonky. Not quite sure why this is but I hope you get the gist.]]></description>
		<content:encoded><![CDATA[<p>Richard,</p>
<p>I&#8217;m assuming that you&#8217;re using Oracle or some other relational database ( and not one of those new-fangled No-SQL ones). I&#8217;m also assuming that points are awarded as follows :</p>
<p>a win is 4 points<br />
a draw is 2 points<br />
a bonus point for scoring 4 or more tries in a game (win or lose)<br />
a bonus point for losing by 7 points or less</p>
<p>So&#8230;you don&#8217;t get another bonus point for 8 tries in a game. Also, you can get up to 2 bonus points if you lose the game, but only one at best, if you win.</p>
<p>I&#8217;ve created a simplified results table. It&#8217;s probably not the way you&#8217;ve implemented it, but it makes this example a bit simpler.</p>
<pre class="brush: sql; title: ; wrap-lines: false; notranslate">
CREATE TABLE team_results(
    team_name VARCHAR2(30),
    opposition VARCHAR2(30),
    points_for NUMBER(3),
    tries NUMBER(2),
    points_ag NUMBER(3))
/

--
-- Now for some test data...
--
INSERT INTO team_results(
    team_name, opposition,
    points_for, tries, points_ag)
VALUES(
    'WALES', 'AUSTRALIA',
    12, 0 , 14)
/

INSERT INTO team_results(
   team_name, opposition,
   points_for, tries, points_ag)
VALUES(
    'WALES', 'NEW ZEALAND',
    12,1,33)
/

INSERT INTO team_results(
    team_name, opposition,
    points_for, tries, points_ag) 
VALUES(
    'WALES', 'FRANCE',
    26,1,17)
/

--
-- Unlike Wales, South Africa have scored four or more tries in a game th‎is season...
-- as well as having a draw...
--

INSERT INTO team_results(
    team_name, opposition,
    points_for, tries, points_ag) 
VALUES( 'SOUTH AFRICA', 'AUSTRALIA',
    31,5,9)
/

INSERT INTO team_results(
    team_name, opposition,
    points_for, tries, points_ag) 
VALUES(
    'SOUTH AFRICA', 'AUSTRALIA',
    19,2,26)
/

INSERT INTO team_results(
    team_name, opposition,
    points_for, tries, points_ag) 
VALUES(
    'SOUTH AFRICA', 'ENGLAND',
    14,1,14)
/

COMMIT;

</pre>
<p>So, if we look at the results:</p>
<pre class="brush: sql; title: ; wrap-lines: false; notranslate">
SELECT team_name, points_for, points_ag, tries 
FROM team_results
ORDER BY team_name
/

TEAM_NAME		       POINTS_FOR  POINTS_AG	  TRIES
------------------------------ ---------- ---------- ----------
SOUTH AFRICA			       19	  26	      2
SOUTH AFRICA			       31	   9	      5
SOUTH AFRICA			       14	  14	      1
WALES				       12	  33	      1
WALES				       12	  14	      0
WALES				       26	  17	      1

6 rows selected.

SQL&gt;
</pre>
<p>&#8230; for Wales, we can see that they&#8217;ll get One point for the loss to Australia ( less than 7 point margin), nothing from their defeat to New Zealand, and four points from their win over France.<br />
This makes a total of 5 points, including 1 bonus points.</p>
<p>As for South Africa, they&#8217;ll get five points from their win over Australia ( 4 plus a bonus point for tries scored),<br />
One for their defeat to Australia ( 7 points or less)<br />
And two points from their draw against England.<br />
This give them a total of 8 points (including 2 bonus points).</p>
<p>To derive this from the raw data, we can use the CASE statement in our query.<br />
We&#8217;re also using an in-line view to tidy up the calculation of overall points</p>
<pre class="brush: sql; highlight: [12,13,14,15,17,18,19,20]; title: ; notranslate">
SELECT team_name, pld, bp, bp+points as total_points
FROM (
    SELECT team_name,
        COUNT(team_name) as pld,
        SUM(
            CASE 
                WHEN points_for &gt; points_ag THEN 4
                WHEN points_for = points_ag THEN 2
                ELSE 0
           END) as points,
        SUM(
            CASE
                WHEN tries &gt;= 4 THEN 1
                ELSE 0
           END) +
        SUM(
            CASE
                WHEN points_ag &gt; points_for AND points_for + 7 &gt;= points_ag THEN 1
                ELSE 0
            END) as bp
    FROM team_results
    GROUP BY team_name)
/

</pre>
<p>Run this and we get :</p>
<pre class="brush: sql; title: ; wrap-lines: false; notranslate">
TEAM_NAME			      PLD	  BP TOTAL_POINTS
------------------------------ ---------- ---------- ------------
SOUTH AFRICA				3	   2		8
WALES					3	   1		5

SQL&gt; 
</pre>
<p>I think the short answer to your question about bonus point calculation is to<br />
use the CASE statement, which as you can see, can handle compound conditions<br />
(lost, but by 7 points or less).</p>
<p>There are a couple of posts which may be of interest ( although they&#8217;re based<br />
on the round-ball game, rather than the oval one).<br />
<a href="http://wp.me/pweWl-fu" rel="nofollow">This post</a> outlines some possibilities when designing the database.<br />
<a href="http://wp.me/pweWl-f4" rel="nofollow">This one</a> makes use of Oracle&#8217;s RANK function so that you can order your result<br />
set by multiple criteria easily.</p>
<p>HTH</p>
<p>Mike</p>
<p>P.S. Sorry some of the formatting is a bit wonky. Not quite sure why this is but I hope you get the gist.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richard</title>
		<link>http://mikesmithers.wordpress.com/2012/12/27/defaulting-null-values-in-sqlloader/#comment-39408</link>
		<dc:creator><![CDATA[Richard]]></dc:creator>
		<pubDate>Fri, 19 Apr 2013 16:13:58 +0000</pubDate>
		<guid isPermaLink="false">http://mikesmithers.wordpress.com/?p=1727#comment-39408</guid>
		<description><![CDATA[Hi!  I was very intrigued by the foregoing article and it gave me some ideas for further development of a database that I run that holds the match statistics for a local youth rugby (i.e. rugby union/football) league.

However, I was wondering do you, or other readers, have any ideas or pointers on how best to handle rugby&#039;s bonus points; i.e. 1 BP for 4 tries and/or 1 BP for losing team coming within 7 points or less of the winning score.

I have written a view for Standings that reads from a Master Results table.  The Standings table is correct except for one statistic: Bonus Points.  Unfortunately, as written, the logic in the View does not distinguish between the losing team coming within 7 points of the winner but awards a bonus point to both teams.  I&#039;ve been tearing my hair out trying to fix this.

I&#039;ve posted on a couple of Forums but have not had a response.
Apologies if this is not the right place or correct protocol for posting.]]></description>
		<content:encoded><![CDATA[<p>Hi!  I was very intrigued by the foregoing article and it gave me some ideas for further development of a database that I run that holds the match statistics for a local youth rugby (i.e. rugby union/football) league.</p>
<p>However, I was wondering do you, or other readers, have any ideas or pointers on how best to handle rugby&#8217;s bonus points; i.e. 1 BP for 4 tries and/or 1 BP for losing team coming within 7 points or less of the winning score.</p>
<p>I have written a view for Standings that reads from a Master Results table.  The Standings table is correct except for one statistic: Bonus Points.  Unfortunately, as written, the logic in the View does not distinguish between the losing team coming within 7 points of the winner but awards a bonus point to both teams.  I&#8217;ve been tearing my hair out trying to fix this.</p>
<p>I&#8217;ve posted on a couple of Forums but have not had a response.<br />
Apologies if this is not the right place or correct protocol for posting.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
