<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    <title>Flashin Leather - SQL</title>
    <link>http://flashinleather.com/</link>
    <description>&quot;If I stand, support me; if I run, shoot me; if I fall, avenge me!&quot;</description>
    <dc:language>en</dc:language>
    <generator>Serendipity 1.4.1 - http://www.s9y.org/</generator>
    <pubDate>Fri, 17 Jul 2009 14:20:38 GMT</pubDate>

    <image>
        <url>http://flashinleather.com/templates/bulletproof/img/s9y_banner_small.png</url>
        <title>RSS: Flashin Leather - SQL - &quot;If I stand, support me; if I run, shoot me; if I fall, avenge me!&quot;</title>
        <link>http://flashinleather.com/</link>
        <width>100</width>
        <height>21</height>
    </image>

<item>
    <title>Case Statement in SQL</title>
    <link>http://flashinleather.com/index.php?/archives/6-Case-Statement-in-SQL.html</link>
            <category>SQL</category>
    
    <comments>http://flashinleather.com/index.php?/archives/6-Case-Statement-in-SQL.html#comments</comments>
    <wfw:comment>http://flashinleather.com/wfwcomment.php?cid=6</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://flashinleather.com/rss.php?version=2.0&amp;type=comments&amp;cid=6</wfw:commentRss>
    

    <author>nospam@example.com (Flashin Leather)</author>
    <content:encoded>
    A &quot;Case&quot; statement in SQL allows for an if/else condition.&lt;br /&gt;
&lt;br /&gt;
SELECT EMPLID, SYSDATE,&lt;strong&gt; CASE&lt;br /&gt;
WHEN A.EFFDT = SYSDATE THEN (EFFSEQ + 1)&lt;br /&gt;
    ELSE 0&lt;br /&gt;
    END AS EFFSEQ&lt;/strong&gt;, EMPL_RCD, &#039;DTA&#039;,&#039;CVG&#039;,COMPANY, POSITION_NBR, REPORTS_TO, SAL_ADMIN_PLAN,&lt;br /&gt;
       CONCAT(RTRIM(PAYGROUP,&#039;W&#039;),&#039;B&#039;) AS PAYGROUP&lt;br /&gt;
FROM PSOFT.PS_JOB a&lt;br /&gt;
WHERE a.paygroup LIKE &#039;%W&#039;&lt;br /&gt;
AND a.effdt = (SELECT MAX(b.effdt) FROM PSOFT.ps_job b&lt;br /&gt;
               WHERE a.emplid = b.emplid&lt;br /&gt;
               AND a.empl_rcd = b.empl_rcd )&lt;br /&gt;
AND a.effseq = (SELECT MAX(c.effseq) FROM PSOFT.ps_job c&lt;br /&gt;
               WHERE a.emplid = c.emplid&lt;br /&gt;
               AND a.empl_rcd = c.empl_rcd&lt;br /&gt;
               AND a.effdt = c.effdt )&lt;br /&gt;
AND a.EMPL_STATUS IN (&#039;A&#039;,&#039;L&#039;,&#039;P&#039;,&#039;S&#039;)&lt;br /&gt;
&lt;br /&gt;
The bold portion of the SQL above allows me to increment the effseq by one where there is a record with an effective date equal to the sysdate.  This is very helpful when trying to insert records into PS_JOB because two records inserted on the same date have to be sequenced to avoid unique constraint errors.&lt;br /&gt;
 
    </content:encoded>

    <pubDate>Fri, 17 Jul 2009 07:07:27 -0700</pubDate>
    <guid isPermaLink="false">http://flashinleather.com/index.php?/archives/6-guid.html</guid>
    
</item>
<item>
    <title>Joining a record to itself</title>
    <link>http://flashinleather.com/index.php?/archives/4-Joining-a-record-to-itself.html</link>
            <category>SQL</category>
    
    <comments>http://flashinleather.com/index.php?/archives/4-Joining-a-record-to-itself.html#comments</comments>
    <wfw:comment>http://flashinleather.com/wfwcomment.php?cid=4</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://flashinleather.com/rss.php?version=2.0&amp;type=comments&amp;cid=4</wfw:commentRss>
    

    <author>nospam@example.com (Flashin Leather)</author>
    <content:encoded>
    This is a trick I learned to compare a row of data in the same record to the previous row and compare fields.  In this case I wanted SQL to return rows where the worker&#039;s jobcode changed or the jobcode was the same but the department changed and a custom indicator was not set.&lt;br /&gt;
&lt;br /&gt;
SELECT *&lt;br /&gt;
FROM psoft.ps_job a, psoft.ps_job b&lt;br /&gt;
WHERE a.emplid = &#039;####&#039;&lt;br /&gt;
AND a.emplid = b.emplid&lt;br /&gt;
AND a.effseq = b.effseq&lt;br /&gt;
AND b.effdt = (SELECT MAX(a2.effdt)&lt;br /&gt;
FROM psoft.ps_job a2&lt;br /&gt;
WHERE a2.emplid = a.emplid&lt;br /&gt;
AND a2.empl_rcd = a.empl_rcd&lt;br /&gt;
AND a2.effdt &lt; a.effdt)&lt;br /&gt;
AND b.effdt &lt;= SYSDATE&lt;br /&gt;
AND a.jobcode &lt;&gt; b.jobcode&lt;br /&gt;
&lt;strong&gt;OR&lt;/strong&gt; a.emplid = &#039;####&#039;&lt;br /&gt;
AND a.emplid = b.emplid&lt;br /&gt;
AND a.effseq = b.effseq&lt;br /&gt;
AND b.effdt = (SELECT MAX(a3.effdt)&lt;br /&gt;
FROM psoft.ps_job a3&lt;br /&gt;
WHERE a3.emplid = a.emplid&lt;br /&gt;
AND a3.empl_rcd = a.empl_rcd&lt;br /&gt;
AND a3.effdt &lt; a.effdt)&lt;br /&gt;
AND b.effdt &lt;= SYSDATE&lt;br /&gt;
AND a.deptid &lt;&gt; b.deptid&lt;br /&gt;
AND a.jobcode = b.jobcode&lt;br /&gt;
AND a.QVC_JOBCD_CHG_IND &lt;&gt; &#039;Y&#039;&lt;br /&gt;
&lt;strong&gt;OR&lt;/strong&gt; a.emplid = &#039;####&#039;&lt;br /&gt;
AND a.emplid = b.emplid&lt;br /&gt;
AND a.effseq = b.effseq&lt;br /&gt;
AND a.effdt = (SELECT MAX(a3.effdt)&lt;br /&gt;
FROM psoft.ps_job a3&lt;br /&gt;
WHERE a3.emplid = a.emplid&lt;br /&gt;
AND a3.empl_rcd = a.empl_rcd&lt;br /&gt;
AND a3.effdt &lt; b.effdt)&lt;br /&gt;
AND a.action = &#039;HIR&#039; &lt;br /&gt;
&lt;br /&gt;
The compare was accomplished by joining, in this case PS_JOB, to itself.&lt;br /&gt;
 
    </content:encoded>

    <pubDate>Mon, 13 Jul 2009 10:59:25 -0700</pubDate>
    <guid isPermaLink="false">http://flashinleather.com/index.php?/archives/4-guid.html</guid>
    
</item>

</channel>
</rss>