Home     |     Java    |     Php General    |     Oracle Database    |     Oracle Server  

MS Dynamics CRM 3.0

  •  Setting up and Configuring Microsoft Dynamics CRM 3.0
  •  Managing Security and Information Access
  •  Entity Customization: Concepts and Attributes
  •  Entity Customization: Forms and Views
  •  Entity Customization: Relationships, Custom Entities, and Site Map
  •  Reporting and Analysis
  •  Workflow
  •  Server-Side SDK
  •  Client-Side SDK
  •  Integration with External Applications
  • Cervo Technologies
    The Right Source to Outsource

    Sharepoint Portal Server KB

    Microsoft CRM Info

    WPF Interview Questions

    SilverLight Interview Qs

    Asp.Net 2.0 Interview Qs

    Asp.NET 1.1 FAQs

    Oracle Interview Questions

    SAP Interview Questions

    Oracle Database

    Help - "Business Day" Problem


    Greetings,
              I have a requirement where an input date will be provided and I
    have to
    update a table with the date previous to input_date (input_date - 1)

    All I have to make sure is input_date - 1 should not be 'SAT' or 'SUN'
    and should not be
    in our holiday table.

    Something like

    UPDATE TABLE1
    SET final_date =(SELECT input_date - 1
                     FROM   ...
                     WHERE  TO_CHAR(TO_DATE ('input_date') - 1,'DY') NOT IN
    ('SAT','SUN')
                     AND    NOT EXISTS (SELECT h_holiday from holiday where h_holiday =
    input_date)

    My question do we need the FROM clause in the subquery? If yes, what
    to specify as this is just an
    input date and not from any table.

    Any help would be appreciated.

    TIA

    On Apr 27, 2:58 pm, "pankaj_wolfhun@yahoo.co.in"

    a) Yes
    b) this is what DUAL was invented for (OK: Originally it was used to
    send printer specific codes to output as the PROMPT command in
    sql*plus didn't yet exist)

    --
    Sybrand Bakker
    Senior Oracle DBA

    -----------------------------------------------Reply-----------------------------------------------

    On Apr 27, 6:04 pm, sybrandb <sybra@gmail.com> wrote:

    Thanks for the reply but I didnt get it.
    Do you mean to say

    SELECT input_date - 1
    FROM    dual
    WHERE TO_CHAR(TO_DATE ('input_date') - 1,'DY') NOT IN ('SAT','SUN')
    AND       NOT EXISTS (SELECT h_holiday from holiday where h_holiday =
    input_date)

    will solve the purpose?

    -----------------------------------------------Reply-----------------------------------------------

    On Apr 27, 3:23 pm, "pankaj_wolfhun@yahoo.co.in"

    Exactly.
    In fact the most efficient way to check for existence of a record is
    select 1
    from dual
    where exists
    (select 1
     from emp where empno = :1)

    Subqueries over DUAL: I love them!

    --
    Sybrand Bakker
    Senior Oracle DBA

    -----------------------------------------------Reply-----------------------------------------------

    "sybrandb" <sybra@gmail.com> a crit dans le message de news: 1177681440.943124.58@r30g2000prh.googlegroups.com...
    | On Apr 27, 3:23 pm, "pankaj_wolfhun@yahoo.co.in"
    |
    | Exactly.
    | In fact the most efficient way to check for existence of a record is
    | select 1
    | from dual
    | where exists
    | (select 1
    | from emp where empno = :1)
    |
    | Subqueries over DUAL: I love them!
    |
    | --
    | Sybrand Bakker
    | Senior Oracle DBA
    |

    Is this faster than:

    select 1 from emp where empno = :1 and rownum = 1;

    --------------------------------------------------------------------------- --
    | Id  | Operation          | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
    --------------------------------------------------------------------------- --
    |   0 | SELECT STATEMENT   |        |     1 |     4 |     0   (0)| 00:00:01 |
    |*  1 |  COUNT STOPKEY     |        |       |       |            |          |
    |*  2 |   INDEX UNIQUE SCAN| PK_EMP |     1 |     4 |     0   (0)| 00:00:01 |
    --------------------------------------------------------------------------- --

    Predicate Information (identified by operation id):
    ---------------------------------------------------

       1 - filter(ROWNUM=1)
       2 - access("EMPNO"=TO_NUMBER(:1))

    Your query:

    --------------------------------------------------------------------------- --
    | Id  | Operation          | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
    --------------------------------------------------------------------------- --
    |   0 | SELECT STATEMENT   |        |     1 |       |     2   (0)| 00:00:01 |
    |*  1 |  FILTER            |        |       |       |            |          |
    |   2 |   FAST DUAL        |        |     1 |       |     2   (0)| 00:00:01 |
    |*  3 |   INDEX UNIQUE SCAN| PK_EMP |     1 |     4 |     0   (0)| 00:00:01 |
    --------------------------------------------------------------------------- --

    Predicate Information (identified by operation id):
    ---------------------------------------------------

       1 - filter( EXISTS (SELECT /*+ */ 0 FROM "EMP" "EMP" WHERE
                  "EMPNO"=TO_NUMBER(:1)))
       3 - access("EMPNO"=TO_NUMBER(:1))

    Regards
    Michel Cadot

    -----------------------------------------------Reply-----------------------------------------------

    On Fri, 27 Apr 2007 18:30:27 +0200, "Michel Cadot"

    I don't see much difference, I must say.
    But I was implicitly referring to the approach I see many times:
    select count(*)
    into dummy
    from emp
    where empno = :emp;
    if dummy > 0 then
    select ename into
    ...
    from emp
    where empno = : emp;

    I even saw this when the predicate wasn't a PK but a FK.

    --
    Sybrand Bakker
    Senior Oracle DBA

    -----------------------------------------------Reply-----------------------------------------------

    <sybra@hccnet.nl> a crit dans le message de news: ndj433pb0t46mim6siqoq1et3cuciai@4ax.com...
    | On Fri, 27 Apr 2007 18:30:27 +0200, "Michel Cadot"

    | <micadot{at}altern{dot}org> wrote:

    |
    | >
    | >"sybrandb" <sybra@gmail.com> a crit dans le message de news: 1177681440.943124.58@r30g2000prh.googlegroups.com...
    | >| On Apr 27, 3:23 pm, "pankaj_wolfhun@yahoo.co.in"
    | >|
    | >| Exactly.
    | >| In fact the most efficient way to check for existence of a record is
    | >| select 1
    | >| from dual
    | >| where exists
    | >| (select 1
    | >| from emp where empno = :1)
    | >|
    | >| Subqueries over DUAL: I love them!
    | >|
    | >| --
    | >| Sybrand Bakker
    | >| Senior Oracle DBA
    | >|
    | >
    | >Is this faster than:
    | >
    | >select 1 from emp where empno = :1 and rownum = 1;
    | >
    | >-------------------------------------------------------------------------- ---
    | >| Id  | Operation          | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
    | >-------------------------------------------------------------------------- ---
    | >|   0 | SELECT STATEMENT   |        |     1 |     4 |     0   (0)| 00:00:01 |
    | >|*  1 |  COUNT STOPKEY     |        |       |       |            |          |
    | >|*  2 |   INDEX UNIQUE SCAN| PK_EMP |     1 |     4 |     0   (0)| 00:00:01 |
    | >-------------------------------------------------------------------------- ---
    | >
    | >Predicate Information (identified by operation id):
    | >---------------------------------------------------
    | >
    | >   1 - filter(ROWNUM=1)
    | >   2 - access("EMPNO"=TO_NUMBER(:1))
    | >
    | >Your query:
    | >
    | >-------------------------------------------------------------------------- ---
    | >| Id  | Operation          | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
    | >-------------------------------------------------------------------------- ---
    | >|   0 | SELECT STATEMENT   |        |     1 |       |     2   (0)| 00:00:01 |
    | >|*  1 |  FILTER            |        |       |       |            |          |
    | >|   2 |   FAST DUAL        |        |     1 |       |     2   (0)| 00:00:01 |
    | >|*  3 |   INDEX UNIQUE SCAN| PK_EMP |     1 |     4 |     0   (0)| 00:00:01 |
    | >-------------------------------------------------------------------------- ---
    | >
    | >Predicate Information (identified by operation id):
    | >---------------------------------------------------
    | >
    | >   1 - filter( EXISTS (SELECT /*+ */ 0 FROM "EMP" "EMP" WHERE
    | >              "EMPNO"=TO_NUMBER(:1)))
    | >   3 - access("EMPNO"=TO_NUMBER(:1))
    | >
    | >
    | >Regards
    | >Michel Cadot
    | >
    |
    | I don't see much difference, I must say.
    | But I was implicitly referring to the approach I see many times:
    | select count(*)
    | into dummy
    | from emp
    | where empno = :emp;
    | if dummy > 0 then
    | select ename into
    | ...
    | from emp
    | where empno = : emp;
    |
    | I even saw this when the predicate wasn't a PK but a FK.
    |
    | --
    | Sybrand Bakker
    | Senior Oracle DBA

    I didn't have any opinion, that was just an open remark.
    I pretty understand your point. :)

    Regards
    Michel Cadot

    -----------------------------------------------Reply-----------------------------------------------

    On Apr 27, 12:41 pm, "Michel Cadot" <micadot{at}altern{dot}org> wrote:

    I think that "fast dual" indicates the answer to this may vary by
    version.  Not to mention, vary by 1000 users doing it 10000 times in
    an update :-O

    jg
    --
    @home.com is bogus.
    "Now you're just screwing with my mind! While I was commenting on your
    last blog, you published a new blog about my blog, about ... I need to
    lie down! ;-)" - Doug Burns

    -----------------------------------------------Reply-----------------------------------------------

    On Apr 28, 3:26 am, joel garry <joel-ga@home.com> wrote:

    Thanks for all the replies.
    Sybrand, I think I am not able to get your point

    Query with dual will only give me the "existence" of the record.

    SELECT 1
    FROM    dual
    WHERE TO_CHAR(TO_DATE ('&2') - 1,'DY') NOT IN ('SAT','SUN')

    Enter value for 2: 28-APR-2007
    old   3: WHERE TO_CHAR(TO_DATE ('&2') - 1,'DY') NOT IN ('SAT','SUN')
    new   3: WHERE TO_CHAR(TO_DATE ('28-APR-2007') - 1,'DY') NOT IN
    ('SAT','SUN')

             1
    ----------
             1

    SELECT 1
    FROM    dual
    WHERE TO_CHAR(TO_DATE ('&2') - 1,'DY') NOT IN ('SAT','SUN')

    Enter value for 2: 30-APR-2007
    old   3: WHERE TO_CHAR(TO_DATE ('&2') - 1,'DY') NOT IN ('SAT','SUN')
    new   3: WHERE TO_CHAR(TO_DATE ('30-APR-2007') - 1,'DY') NOT IN
    ('SAT','SUN')

    no rows selected

    What I want is the business date prev to the date provided.  So if I
    enter 30-APR-2007, I should get 27-Apr-2007

    Sorry if I am not able to get your point or If I was not clear with my
    requirement.

    Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc