<?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>Cyril Hanquez &#187; Database</title>
	<atom:link href="http://cyrilhanquez.com/blog/category/database/feed/" rel="self" type="application/rss+xml" />
	<link>http://cyrilhanquez.com/blog</link>
	<description>Rich Internet Application developer</description>
	<lastBuildDate>Mon, 07 Jun 2010 08:12:53 +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>sneak peak at ColdFusion&#8217;s future</title>
		<link>http://cyrilhanquez.com/blog/2009/04/28/sneak-peak-cf/</link>
		<comments>http://cyrilhanquez.com/blog/2009/04/28/sneak-peak-cf/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 14:08:42 +0000</pubDate>
		<dc:creator>Cyril H.</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Ben Forta]]></category>
		<category><![CDATA[Centaur]]></category>
		<category><![CDATA[ORM]]></category>

		<guid isPermaLink="false">http://cyrilhanquez.com/blog/?p=392</guid>
		<description><![CDATA[Ben Forta just finished his quick European trip (UK, Belgium and Netherlands) to present &#8220;a sneak peak at ColdFusion&#8217;s future&#8221;. I was lucky enough to see him twice: the first time at the European Commission in a meeting room packed of 80 developers, the second time in Brussels in front of 45 developers. Both presentations started with [...]]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_blue" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fcyrilhanquez.com%252Fblog%252F2009%252F04%252F28%252Fsneak-peak-cf%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22sneak%20peak%20at%20ColdFusion%27s%20future%22%20%7D);"></div>
<p style="text-align: justify;"><a onclick="pageTracker._trackPageview('/outbound/article/forta.com');" href="http://forta.com/" target="_blank"><strong><br />
Ben Forta</strong></a> just finished his quick European trip (UK, Belgium and Netherlands) to present <strong>&#8220;a sneak peak at ColdFusion&#8217;s future&#8221;</strong>. I was lucky enough to see him twice: the first time at the <a href="http://ec.europa.eu" target="_blank">European Commission</a> in a meeting room packed of 80 developers, the second time in Brussels in front of 45 developers.</p>
<p style="text-align: justify;">Both presentations started with a quick demo of <a href="http://opensource.adobe.com/wiki/display/blazeds/BlazeDS/" target="_blank">BlazeDS</a> data push and <a href="http://www.adobe.com/products/livecycle/dataservices/" target="_blank">LCDS</a> built-in conflict management: even if I&#8217;ve already seen this demo several times, it&#8217;s always nice to see the reaction of the audience. Will <a href="http://opensource.adobe.com/wiki/display/blazeds/BlazeDS/" target="_blank">BlazeDS</a> replace <a href="http://www.adobe.com/products/livecycle/dataservices/" target="_blank">LCDS</a> Express in Centaur ? No words on that yet&#8230; <img src='http://cyrilhanquez.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p style="text-align: justify;">Second part focused on Centaur and Bolt: I really loved the introduction tag line</p>
<blockquote style="text-align: center;"><p><strong>&#8221; Advancing rapid application development<br />
and turning developers into heroes. &#8221;<br />
</strong></p></blockquote>
<p>Now let&#8217;s see what has been shown.</p>
<p><span id="more-392"></span></p>
<p><strong>ColdFusion Exposed Services Layer (ESL)</strong></p>
<p style="text-align: justify;">This is a feature for non <a href="http://www.adobe.com/products/coldfusion/" target="_blank">ColdFusion</a> developers: you will be able to access, using your own language (PHP, .NET,&#8230;) and via SOAP or AMF,  integrated CF services without writing any CFML code! Those services includes Query Service, Mail, Generation and Manipulation of PDF files, Imaging, Charting etc&#8230;  Those ESL will be also available for <a href="http://www.adobe.com/products/flex/" target="_blank">Flex</a>/<a href="http://www.adobe.com/products/air/" target="_blank">AIR</a> developers via CF-ESL.</p>
<p>For me It sounds pretty interesting to use the same services across different applications/languages instead of having to buy 3rd party extensions (when available),  no? <img src='http://cyrilhanquez.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><strong>Local/Remote Database Synchronization (CF/AIR)</strong></p>
<p style="text-align: justify;">Centaur will be able to handle data synchronisation between an <a href="http://www.adobe.com/products/air/" target="_blank">AIR</a> SQLite DB and a <a href="http://www.adobe.com/products/coldfusion/" target="_blank">ColdFusion</a> datasource. It will make easier the development of Offline <a href="http://www.adobe.com/products/air/" target="_blank">AIR</a> apps using a <a href="http://www.adobe.com/products/coldfusion/" target="_blank">ColdFusion</a> backend. W00t!</p>
<p><strong>CFScript Enhancements</strong></p>
<p style="text-align: justify;">Here you will find<em> Explicit local scope for private function variables</em>, <em>implicit getters/setters </em>(Yeahh!), <em>Import &amp; New keyword</em>.</p>
<p style="text-align: justify;">After seeing that I was wondering why Adobe did not decide to replace CFScript with ActionScript 3.0? If you were at MAX last year, you have probably seen this demo of server side ActionScript in Centaur&#8230; why maintaining another scripting language so close to AS 3.0?<strong> </strong>It would have made things easier&#8230;  Anyone agree with that?</p>
<p><strong id="g4l20">ORM (Hibernate)</strong></p>
<p style="text-align: justify;">Centaur implements Object Relational Mapping via Hibernate: ORM provides Database vendor independence, caching, concurrency via a representation of your relational data in an Object Model. I&#8217;m not that comfortable talking about ORM so I will make that one a bit short. I can only tell you that Bolt has full support for ORM and generate all the code for you, even if we only saw a simple example <img src='http://cyrilhanquez.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><strong>Bolt</strong></p>
<p style="text-align: justify;">Bolt is the new <a href="http://www.adobe.com/products/coldfusion/" target="_blank">ColdFusion</a> IDE: it&#8217;s an Eclipse plugin like Flex Builder, so people doing <a href="http://www.adobe.com/products/flex/" target="_blank">Flex</a> development will be happy with the full integration. It has Server management, server monitoring, services introspection, code generation, etc&#8230; what is interesting also is that you can create extension for Bolt using CFML code! So you will be able to create plugins to do code generation in your favorite framework <img src='http://cyrilhanquez.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p style="text-align: justify;">I think that&#8217;s almost everything that has been covered. I was really happy to see some many enthusiastic <a href="http://www.adobe.com/products/coldfusion/" target="_blank">ColdFusion</a> developers&#8230; haven&#8217;t seen that for  a while <img src='http://cyrilhanquez.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  And remember that those features are only a small part of what will be available in the release version.</p>
<p style="text-align: justify;">A last thing to finish: if you don&#8217;t know yet <strong><a href="http://www.englebert.be/blog/" target="_blank">Claude Englebert</a></strong>, the <strong>EMEA ColdFusion Product Specialist</strong>, don&#8217;t hesitate to get in touch with him for anything related to CF (events, User Group, promotion, support&#8230;)!</p>
<p style="text-align: justify;">I know <a onclick="pageTracker._trackPageview('/outbound/article/forta.com');" href="http://forta.com/" target="_blank"><strong>Ben Forta</strong></a> loves when people are playing with photoshop <img src='http://cyrilhanquez.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p style="text-align: center;"><strong><a href="http://forta.com/" target="_blank"><strong><img title="ben_master" src="http://cyrilhanquez.com/blog/wp-content/uploads/2009/04/ben_master.png" alt="ben_master" width="140" height="300" /></strong></a></strong> <strong><a href="http://forta.com/" target="_blank"><strong><img title="claude_padawan" src="http://cyrilhanquez.com/blog/wp-content/uploads/2009/04/claude_padawan.png" alt="claude_padawan" width="310" height="299" /></strong></a></strong></p>

]]></content:encoded>
			<wfw:commentRss>http://cyrilhanquez.com/blog/2009/04/28/sneak-peak-cf/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>A lovely way to group dates</title>
		<link>http://cyrilhanquez.com/blog/2008/07/16/a-lovely-way-of-grouping-dates/</link>
		<comments>http://cyrilhanquez.com/blog/2008/07/16/a-lovely-way-of-grouping-dates/#comments</comments>
		<pubDate>Wed, 16 Jul 2008 22:37:59 +0000</pubDate>
		<dc:creator>Cyril H.</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[User Interface]]></category>

		<guid isPermaLink="false">http://cyrilhanquez.com/blog/?p=35</guid>
		<description><![CDATA[In my current Flex project I need to create an interface that will replace the email client of the users. Many of them are using Outlook, so I would like to reproduce the same look and behavior. The new advanced datagrid in Flex 3 will come in handy to achieve the task, but there is one specific behavior [...]]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_blue" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fcyrilhanquez.com%252Fblog%252F2008%252F07%252F16%252Fa-lovely-way-of-grouping-dates%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22A%20lovely%20way%20to%20group%20dates%22%20%7D);"></div>
<p style="text-align: justify;">In my current Flex project I need to create an interface that will replace the email client of the users. Many of them are using Outlook, so I would like to reproduce the same look and behavior. The new advanced datagrid in Flex 3 will come in handy to achieve the task, but there is one specific behavior that I would like to reproduce, it&#8217;s the way Outlook is grouping the dates : it creates the following groups :</p>
<ul>
<li>
<div style="text-align: justify;"><strong>Today</strong></div>
</li>
<li>
<div style="text-align: justify;"><strong>Yesterday</strong></div>
</li>
<li>
<div style="text-align: justify;"><strong>&lt;NAME OF DAY&gt;</strong> <em>- if in the same week as the current date</em></div>
</li>
<li>
<div style="text-align: justify;"><strong>Last Week</strong></div>
</li>
<li>
<div style="text-align: justify;"><strong>Two Weeks ago</strong></div>
</li>
<li>
<div style="text-align: justify;"><strong>Last Month</strong></div>
</li>
<li>
<div style="text-align: justify;"><strong>Older</strong></div>
</li>
</ul>
<p style="text-align: justify;">It&#8217;s also easily expendable to the Future (Tomorrow, In two days&#8230;). So I created an Oracle function which generate the correct group label for a given date.</p>
<p><span id="more-35"></span></p>

<div class="wp_syntax"><div class="code"><pre class="plsql" style="font-family:monospace;"><span style="color: #00F;">CREATE</span> <span style="color: #00F;">OR</span> <span style="color: #000;">REPLACE</span> <span style="color: #00F;">PACKAGE</span> TRIS_UTILS <span style="color: #00F;">AUTHID</span> CURRENT_USER <span style="color: #00F;">AS</span>
<span style="color: #080; font-style: italic;">/*******************************************************************
NAME:      TRIS_UTILS
PURPOSE:   Utilities functions.
REVISION:  Ver        Date            Author          Description
          -----     -------     ---------------  ------------------
           1.0    15/07/2008    Cyril Hanquez    Creation  
*******************************************************************/</span>
&nbsp;
<span style="color: #080; font-style: italic;">/* compare a_date with sysdate and return
    the corresponding group label            */</span>  
<span style="color: #00F;">FUNCTION</span> get_grouping_date_name<span style="color: #00F;">&#40;</span>a_date <span style="color: #00F;">IN</span> <span style="color: #00F;">DATE</span><span style="color: #00F;">&#41;</span> <span style="color: #00F;">RETURN</span> <span style="color: #00F;">VARCHAR2</span><span style="color: #00F;">;</span>
&nbsp;
<span style="color: #00F;">END</span> TRIS_UTILS<span style="color: #00F;">;</span>
<span style="color: #00F;">/</span>
&nbsp;
<span style="color: #00F;">CREATE</span> <span style="color: #00F;">OR</span> <span style="color: #000;">REPLACE</span> <span style="color: #00F;">PACKAGE</span> <span style="color: #00F;">BODY</span> TRIS_UTILS <span style="color: #00F;">AS</span>
<span style="color: #080; font-style: italic;">/*******************************************************************
NAME:      TRIS_UTILS
PURPOSE:   Utilities functions.
REVISION:  Ver        Date            Author          Description
          -----     -------     ---------------  ------------------
           1.0    15/07/2008    Cyril Hanquez    Creation  
*******************************************************************/</span>
<span style="color: #00F;">FUNCTION</span> get_grouping_date_name<span style="color: #00F;">&#40;</span>a_date <span style="color: #00F;">IN</span> <span style="color: #00F;">DATE</span><span style="color: #00F;">&#41;</span> <span style="color: #00F;">RETURN</span> <span style="color: #00F;">VARCHAR2</span> <span style="color: #00F;">IS</span>
&nbsp;
return_var <span style="color: #00F;">VARCHAR2</span><span style="color: #00F;">&#40;</span><span style="color: #800;">50</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">;</span>
&nbsp;
<span style="color: #00F;">BEGIN</span>
&nbsp;
<span style="color: #00F;">CASE</span>
   <span style="color: #080; font-style: italic;">/* In Oracle date1-date2 returns a number of days
      It's equivalent to DATEDIFF(day, a_date, getdate()) */</span>
   <span style="color: #00F;">WHEN</span> <span style="color: #000;">TRUNC</span><span style="color: #00F;">&#40;</span><span style="color: #000;">SYSDATE</span> <span style="color: #00F;">-</span> a_date<span style="color: #00F;">&#41;</span> <span style="color: #00F;">=</span> <span style="color: #800;">0</span>
       <span style="color: #00F;">THEN</span> return_var <span style="color: #00F;">:=</span> <span style="color: #F00;">'Today'</span><span style="color: #00F;">;</span>
   <span style="color: #080; font-style: italic;">/* parameter 'IW' is returning the Week of year
      but we must also verify that we are in a valid period */</span>
   <span style="color: #00F;">WHEN</span> <span style="color: #00F;">&#40;</span><span style="color: #00F;">&#40;</span><span style="color: #000;">TO_CHAR</span><span style="color: #00F;">&#40;</span><span style="color: #000;">SYSDATE</span><span style="color: #00F;">,</span><span style="color: #F00;">'IW'</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">-</span><span style="color: #000;">TO_CHAR</span><span style="color: #00F;">&#40;</span>a_date<span style="color: #00F;">,</span><span style="color: #F00;">'IW'</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">&#41;</span> <span style="color: #00F;">=</span> <span style="color: #800;">0</span> <span style="color: #00F;">AND</span>
            <span style="color: #080; font-style: italic;">/* between -6 AND +6 would be enough
               7 days a week -1 because today returns 0
               equivalent to ABS(TRUNC(SYSDATE - a_date)) &lt;= 8 */</span>
            <span style="color: #000;">TRUNC</span><span style="color: #00F;">&#40;</span><span style="color: #000;">SYSDATE</span> <span style="color: #00F;">-</span> a_date<span style="color: #00F;">&#41;</span> <span style="color: #00F;">BETWEEN</span> <span style="color: #00F;">-</span><span style="color: #800;">8</span> <span style="color: #00F;">AND</span> <span style="color: #800;">8</span><span style="color: #00F;">&#41;</span>
       <span style="color: #00F;">THEN</span>
       <span style="color: #00F;">CASE</span>
          <span style="color: #00F;">WHEN</span> <span style="color: #000;">TRUNC</span><span style="color: #00F;">&#40;</span><span style="color: #000;">SYSDATE</span> <span style="color: #00F;">-</span> a_date<span style="color: #00F;">&#41;</span> <span style="color: #00F;">=</span> <span style="color: #800;">1</span>
             <span style="color: #00F;">THEN</span> return_var <span style="color: #00F;">:=</span> <span style="color: #F00;">'Yesterday'</span><span style="color: #00F;">;</span>
          <span style="color: #00F;">WHEN</span> <span style="color: #000;">TRUNC</span><span style="color: #00F;">&#40;</span><span style="color: #000;">SYSDATE</span> <span style="color: #00F;">-</span> a_date<span style="color: #00F;">&#41;</span> <span style="color: #00F;">=</span> <span style="color: #00F;">-</span><span style="color: #800;">1</span>
             <span style="color: #00F;">THEN</span> return_var <span style="color: #00F;">:=</span> <span style="color: #F00;">'Tomorrow'</span><span style="color: #00F;">;</span>
          <span style="color: #00F;">WHEN</span> <span style="color: #000;">ABS</span><span style="color: #00F;">&#40;</span><span style="color: #000;">SYSDATE</span> <span style="color: #00F;">-</span> a_date<span style="color: #00F;">&#41;</span> <span style="color: #00F;">&gt;</span> <span style="color: #800;">1</span>
             <span style="color: #080; font-style: italic;">/* We are returning the Name of day here */</span>
             <span style="color: #00F;">THEN</span> return_var <span style="color: #00F;">:=</span> <span style="color: #000;">INITCAP</span><span style="color: #00F;">&#40;</span><span style="color: #000;">TO_CHAR</span><span style="color: #00F;">&#40;</span>a_date<span style="color: #00F;">,</span><span style="color: #F00;">'DAY'</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">;</span>
       <span style="color: #00F;">END</span> <span style="color: #00F;">CASE</span><span style="color: #00F;">;</span>
   <span style="color: #00F;">WHEN</span> <span style="color: #00F;">&#40;</span><span style="color: #00F;">&#40;</span><span style="color: #000;">TO_CHAR</span><span style="color: #00F;">&#40;</span><span style="color: #000;">SYSDATE</span><span style="color: #00F;">,</span><span style="color: #F00;">'IW'</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">-</span><span style="color: #000;">TO_CHAR</span><span style="color: #00F;">&#40;</span>a_date<span style="color: #00F;">,</span><span style="color: #F00;">'IW'</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">&#41;</span> <span style="color: #00F;">=</span> <span style="color: #800;">1</span> <span style="color: #00F;">AND</span>
           <span style="color: #080; font-style: italic;">/* &lt;=13 would be enough */</span>
           <span style="color: #000;">ABS</span><span style="color: #00F;">&#40;</span><span style="color: #000;">SYSDATE</span> <span style="color: #00F;">-</span> a_date<span style="color: #00F;">&#41;</span> <span style="color: #00F;">&lt;=</span> <span style="color: #800;">15</span><span style="color: #00F;">&#41;</span>
      <span style="color: #00F;">THEN</span> return_var <span style="color: #00F;">:=</span> <span style="color: #F00;">'Last Week'</span><span style="color: #00F;">;</span>
   <span style="color: #00F;">WHEN</span> <span style="color: #00F;">&#40;</span><span style="color: #00F;">&#40;</span><span style="color: #000;">TO_CHAR</span><span style="color: #00F;">&#40;</span><span style="color: #000;">SYSDATE</span><span style="color: #00F;">,</span><span style="color: #F00;">'IW'</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">-</span><span style="color: #000;">TO_CHAR</span><span style="color: #00F;">&#40;</span>a_date<span style="color: #00F;">,</span><span style="color: #F00;">'IW'</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">&#41;</span> <span style="color: #00F;">=</span> <span style="color: #00F;">-</span><span style="color: #800;">1</span> <span style="color: #00F;">AND</span>
           <span style="color: #080; font-style: italic;">/* &lt;=13 would be enough */</span>
           <span style="color: #000;">ABS</span><span style="color: #00F;">&#40;</span><span style="color: #000;">SYSDATE</span> <span style="color: #00F;">-</span> a_date<span style="color: #00F;">&#41;</span> <span style="color: #00F;">&lt;=</span> <span style="color: #800;">15</span><span style="color: #00F;">&#41;</span>
      <span style="color: #00F;">THEN</span> return_var <span style="color: #00F;">:=</span> <span style="color: #F00;">'Next Week'</span><span style="color: #00F;">;</span>
   <span style="color: #00F;">WHEN</span> <span style="color: #00F;">&#40;</span><span style="color: #00F;">&#40;</span><span style="color: #000;">TO_CHAR</span><span style="color: #00F;">&#40;</span><span style="color: #000;">SYSDATE</span><span style="color: #00F;">,</span><span style="color: #F00;">'IW'</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">-</span><span style="color: #000;">TO_CHAR</span><span style="color: #00F;">&#40;</span>a_date<span style="color: #00F;">,</span><span style="color: #F00;">'IW'</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">&#41;</span> <span style="color: #00F;">=</span> <span style="color: #800;">2</span> <span style="color: #00F;">AND</span>
           <span style="color: #080; font-style: italic;">/* &lt;=20 would be enough */</span>
           <span style="color: #000;">ABS</span><span style="color: #00F;">&#40;</span><span style="color: #000;">SYSDATE</span> <span style="color: #00F;">-</span> a_date<span style="color: #00F;">&#41;</span> <span style="color: #00F;">&lt;=</span> <span style="color: #800;">22</span><span style="color: #00F;">&#41;</span>
      <span style="color: #00F;">THEN</span> return_var <span style="color: #00F;">:=</span> <span style="color: #F00;">'Two Weeks Ago'</span><span style="color: #00F;">;</span>
   <span style="color: #00F;">WHEN</span> <span style="color: #00F;">&#40;</span><span style="color: #00F;">&#40;</span><span style="color: #000;">TO_CHAR</span><span style="color: #00F;">&#40;</span><span style="color: #000;">SYSDATE</span><span style="color: #00F;">,</span><span style="color: #F00;">'IW'</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">-</span><span style="color: #000;">TO_CHAR</span><span style="color: #00F;">&#40;</span>a_date<span style="color: #00F;">,</span><span style="color: #F00;">'IW'</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">&#41;</span> <span style="color: #00F;">=</span> <span style="color: #00F;">-</span><span style="color: #800;">2</span> <span style="color: #00F;">AND</span>
           <span style="color: #080; font-style: italic;">/* &lt;=20 would be enough */</span>
           <span style="color: #000;">ABS</span><span style="color: #00F;">&#40;</span><span style="color: #000;">SYSDATE</span> <span style="color: #00F;">-</span> a_date<span style="color: #00F;">&#41;</span> <span style="color: #00F;">&lt;=</span> <span style="color: #800;">22</span><span style="color: #00F;">&#41;</span>
      <span style="color: #00F;">THEN</span> return_var <span style="color: #00F;">:=</span> <span style="color: #F00;">'In Two Weeks'</span><span style="color: #00F;">;</span>
   <span style="color: #00F;">WHEN</span> <span style="color: #00F;">&#40;</span><span style="color: #00F;">&#40;</span><span style="color: #000;">TO_CHAR</span><span style="color: #00F;">&#40;</span><span style="color: #000;">SYSDATE</span><span style="color: #00F;">,</span><span style="color: #F00;">'IW'</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">-</span><span style="color: #000;">TO_CHAR</span><span style="color: #00F;">&#40;</span>a_date<span style="color: #00F;">,</span><span style="color: #F00;">'IW'</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">&#41;</span> <span style="color: #00F;">=</span> <span style="color: #800;">3</span> <span style="color: #00F;">AND</span>
           <span style="color: #080; font-style: italic;">/* &lt;=27 would be enough */</span>
           <span style="color: #000;">ABS</span><span style="color: #00F;">&#40;</span><span style="color: #000;">SYSDATE</span> <span style="color: #00F;">-</span> a_date<span style="color: #00F;">&#41;</span> <span style="color: #00F;">&lt;=</span> <span style="color: #800;">29</span><span style="color: #00F;">&#41;</span>
      <span style="color: #00F;">THEN</span> return_var <span style="color: #00F;">:=</span> <span style="color: #F00;">'Three Weeks Ago'</span> <span style="color: #00F;">;</span>
   <span style="color: #00F;">WHEN</span> <span style="color: #00F;">&#40;</span><span style="color: #00F;">&#40;</span><span style="color: #000;">TO_CHAR</span><span style="color: #00F;">&#40;</span><span style="color: #000;">SYSDATE</span><span style="color: #00F;">,</span><span style="color: #F00;">'IW'</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">-</span><span style="color: #000;">TO_CHAR</span><span style="color: #00F;">&#40;</span>a_date<span style="color: #00F;">,</span><span style="color: #F00;">'IW'</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">&#41;</span> <span style="color: #00F;">=</span> <span style="color: #00F;">-</span><span style="color: #800;">3</span> <span style="color: #00F;">AND</span>
           <span style="color: #080; font-style: italic;">/* &lt;=27 would be enough */</span>
           <span style="color: #000;">ABS</span><span style="color: #00F;">&#40;</span><span style="color: #000;">SYSDATE</span> <span style="color: #00F;">-</span> a_date<span style="color: #00F;">&#41;</span> <span style="color: #00F;">&lt;=</span> <span style="color: #800;">29</span><span style="color: #00F;">&#41;</span>
      <span style="color: #00F;">THEN</span> return_var <span style="color: #00F;">:=</span> <span style="color: #F00;">'In Three Weeks'</span><span style="color: #00F;">;</span>
   <span style="color: #00F;">WHEN</span> <span style="color: #00F;">&#40;</span><span style="color: #00F;">&#40;</span><span style="color: #000;">TO_CHAR</span><span style="color: #00F;">&#40;</span><span style="color: #000;">SYSDATE</span><span style="color: #00F;">,</span><span style="color: #F00;">'MM'</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">-</span><span style="color: #000;">TO_CHAR</span><span style="color: #00F;">&#40;</span>a_date<span style="color: #00F;">,</span><span style="color: #F00;">'MM'</span><span style="color: #00F;">&#41;</span> <span style="color: #00F;">=</span> <span style="color: #800;">1</span> <span style="color: #00F;">AND</span>
           <span style="color: #080; font-style: italic;">/* current month + 1 month so a maximum of 62 days */</span>
           <span style="color: #000;">ABS</span><span style="color: #00F;">&#40;</span><span style="color: #000;">SYSDATE</span> <span style="color: #00F;">-</span> a_date<span style="color: #00F;">&#41;</span> <span style="color: #00F;">&lt;=</span> <span style="color: #800;">62</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">&#41;</span>
      <span style="color: #00F;">THEN</span> return_var <span style="color: #00F;">:=</span> <span style="color: #F00;">'Last Month'</span> <span style="color: #00F;">;</span>
   <span style="color: #00F;">WHEN</span> <span style="color: #00F;">&#40;</span><span style="color: #00F;">&#40;</span><span style="color: #000;">TO_CHAR</span><span style="color: #00F;">&#40;</span><span style="color: #000;">SYSDATE</span><span style="color: #00F;">,</span><span style="color: #F00;">'MM'</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">-</span><span style="color: #000;">TO_CHAR</span><span style="color: #00F;">&#40;</span>a_date<span style="color: #00F;">,</span><span style="color: #F00;">'MM'</span><span style="color: #00F;">&#41;</span> <span style="color: #00F;">=</span> <span style="color: #00F;">-</span><span style="color: #800;">1</span> <span style="color: #00F;">AND</span>
           <span style="color: #080; font-style: italic;">/* current month + 1 month so a maximum of 62 days */</span>
           <span style="color: #000;">ABS</span><span style="color: #00F;">&#40;</span><span style="color: #000;">SYSDATE</span> <span style="color: #00F;">-</span> a_date<span style="color: #00F;">&#41;</span> <span style="color: #00F;">&lt;=</span> <span style="color: #800;">62</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">&#41;</span>
      <span style="color: #00F;">THEN</span> return_var <span style="color: #00F;">:=</span> <span style="color: #F00;">'Next Month'</span><span style="color: #00F;">;</span>
   <span style="color: #080; font-style: italic;">/* in other cases just check if the date is in the future... */</span>
   <span style="color: #00F;">WHEN</span> <span style="color: #000;">SIGN</span><span style="color: #00F;">&#40;</span><span style="color: #000;">SYSDATE</span> <span style="color: #00F;">-</span> a_date<span style="color: #00F;">&#41;</span> <span style="color: #00F;">=</span> <span style="color: #00F;">-</span><span style="color: #800;">1</span>
      <span style="color: #00F;">THEN</span> return_var <span style="color: #00F;">:=</span> <span style="color: #F00;">'Further'</span><span style="color: #00F;">;</span>
   <span style="color: #080; font-style: italic;">/* ...or in the past */</span>
   <span style="color: #00F;">WHEN</span> <span style="color: #000;">SIGN</span><span style="color: #00F;">&#40;</span><span style="color: #000;">SYSDATE</span> <span style="color: #00F;">-</span> a_date<span style="color: #00F;">&#41;</span> <span style="color: #00F;">=</span> <span style="color: #800;">1</span>
      <span style="color: #00F;">THEN</span> return_var <span style="color: #00F;">:=</span> <span style="color: #F00;">'Older'</span><span style="color: #00F;">;</span>
   <span style="color: #080; font-style: italic;">/* if the date is null, do something */</span>
   <span style="color: #00F;">ELSE</span> return_var <span style="color: #00F;">:=</span> <span style="color: #F00;">'---'</span><span style="color: #00F;">;</span>
<span style="color: #00F;">END</span> <span style="color: #00F;">CASE</span><span style="color: #00F;">;</span>
&nbsp;
<span style="color: #00F;">RETURN</span> return_var<span style="color: #00F;">;</span>
&nbsp;
<span style="color: #00F;">END</span><span style="color: #00F;">;</span>
&nbsp;
<span style="color: #00F;">END</span> TRIS_UTILS<span style="color: #00F;">;</span>
<span style="color: #00F;">/</span></pre></div></div>

<p style="text-align: justify;">Now that we have our group labels generated, we should take care about the sorting. Its quite easy in fact, just use the DATEDIFF. To test it just use the following SQL :</p>

<div class="wp_syntax"><div class="code"><pre class="plsql" style="font-family:monospace;"><span style="color: #00F;">SELECT</span> <span style="color: #00F;">&lt;</span>your_date<span style="color: #00F;">&gt;</span> <span style="color: #00F;">AS</span> MY_DATE<span style="color: #00F;">,</span>
TRIS_UTILS<span style="color: #00F;">.</span><span style="color: #00F;">&#40;</span>get_grouping_date_name<span style="color: #00F;">,&lt;</span>your_date<span style="color: #00F;">&gt;</span><span style="color: #00F;">&#41;</span> <span style="color: #00F;">AS</span> <span style="color: #00F;">GROUP</span> LABEL<span style="color: #00F;">,</span>
<span style="color: #00F;">&#40;</span>SYSDATE<span style="color: #00F;">-&lt;</span>your_date<span style="color: #00F;">&gt;</span><span style="color: #00F;">&#41;</span> <span style="color: #00F;">AS</span> DATE_SORT
<span style="color: #00F;">FROM</span> DUAL</pre></div></div>

<p style="text-align: justify;">In a next blog post I will share the Flex code that I wrote to generate the &#8220;Outlook like&#8221; interface. Feel free to comment and suggest any enhancement <img src='http://cyrilhanquez.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>

]]></content:encoded>
			<wfw:commentRss>http://cyrilhanquez.com/blog/2008/07/16/a-lovely-way-of-grouping-dates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
