Any Function in T-SQL thats similar to GREATEST() IN Orcl.

Is there any Function in T-SQL thats similar to GREATEST() IN Orcl?
Iam trying to find the greatest of two DATETIME datatype Fields in my 'select's.
If there is no in built function, Whats the best approach?

MKR,
If you are using SS 2005, you could use the new operator UNPIVOT.
Code Block
DECLARE @MyTable table
( RowID int IDENTITY,
Date1 datetime,
Date2 datetime,
Date3 datetime NOT NULL DEFAULT getdate()
INSERT INTO @MyTable VALUES ( '2007/01/01', '2007/02/01', '2007/01/31' )
INSERT INTO @MyTable VALUES ( '2007/10/10', '2007/11/01', DEFAULT )
INSERT INTO @MyTable VALUES ( '2007/12/01', '2007/12/05', '2007/12/06' )
SELECT
a
.RowID,
a.Date1,
a.Date2,
a.Date3,
b.Greatest
FROM
@MyTable
AS a
INNER JOIN
SELECT
RowID
MAX([Value]) AS Greatest
FROM
@MyTable
UNPIVOT
[Value]
FOR ColumnName IN ([Date1], [Date2], [Date3])
) AS unpvt
GROUP BY
RowID
) AS b
ON a.RowID = b.RowID
ORDER BY
a
.RowID
-- OR
SELECT
a
.*, b.Greatest
FROM
@MyTable
AS a
CROSS APPLY
SELECT
MAX(Value) AS Greatest
FROM
@MyTable
UNPIVOT
[Value]
FOR ColumnName IN ([Date1], [Date2], [Date3])
) AS unpvt
WHERE
unpvt
.RowID = a.RowID
) AS b
ORDER BY
a
.RowID
GO
AMB

Similar Messages

  • How to call a function with pl/sql

    How does one call a function with pl/sql that uses a function?

    Hi,
    How does one call a function with pl/sql that uses a
    function?I'm not sure what you mean.
    In PL/SQL function can be used just about anywhere where an expression (with the same data type that the function returns). Arpit gave a very common example.
    Here's another example, where all the functions take a single NUMBER argument and return a NUMBER, so they can all be used in places where NUMBERs are used:
    IF  fun_a (fun_b (0)) < fun_c (1)
    THEN
        UPDATE  table_x
        SET     column_y = fun_d (2)
        WHERE   column_z = fun_e (ROUND ((fun_f (3), fun_g (4)));You call a function simply by using its name, followed by its argument list, if any.
    If the function is in a package, you must call it with the package name, like "pk_foo.bar (1, 2, 3)", unless the call comes from within the same package.
    If the function is owned by someone else, you must give the owner name, like "scott.bar (SYSDATE)" or "scott.pk_foo.bar (1, 2, 3)". You can create synonyms to avoid having to name the owner.

  • Function module or BAPI that is used to update the records in RBKP table.

    Hello All,
    Can anybody please give me the name of any Function module or BAPI that is used to update the records in RBKP table.
    Please help me
      I need to change the fiscal year in RBKP table
    Thanks in Advance,
    Regards,
    LIJO

    Hi,
    You can use the BAPIs,
    BAPI_ACC_INVOICE_RECEIPT_CHECK Accounting: Check Invoice Receipt (OAG: LOAD PAYABLE)
    BAPI_ACC_INVOICE_RECEIPT_POST  Accounting: Post Invoice Receipt (OAG: LOAD PAYABLE)
    Hope this helps.
    Regards,
    Renjith Michael.

  • Any functional module to get financial document based on billing document

    hi all,
    do we have any functional module to get accounting document (bseg-BELNR) based on billing document (bseg-VBELN)?
    i have a requirement to retrieve the clearing document (bseg-augcp) & date(bseg-augdt) from BSEG with billing document.
    billing document is not a key, so i would like to retrieve the accounting document from any function module and use that to get clearing document (bseg-augcp) & date(bseg-augdt).
    thanks.

    hi all,
    i got other option to get this....thanks.
          select single * from bkpf
          where bukrs = <data>-werks
            and AWTYP = 'VBRK'
            and AWKEY = billing doc.
          if sy-subrc EQ 0.
            select single * from bseg
            where bukrs = bkpf-bukrs
              and belnr = bkpf-belnr
              and gjahr = bkpf-gjahr.
            if sy-subrc EQ 0.
              <data>-AUGDT = bseg-augdt.
              <data>-AUGBL = bseg-augbl.
            endif.

  • SQL Query (PL/SQL Function Body returning SQL query) doesn't return any row

    I have a region with the following type:
    SQL Query (PL/SQL Function Body returning SQL query).
    In a search screen the users can enter different numbers, separated by an ENTER.
    I want to check these numbers by replacing the ENTER, which is CHR(13) || CHR(10) I believe, with commas. And then I can use it like this: POD IN (<<text>>).
    It's something like this:
    If (:P30_POD Is Not Null) Then
    v_where := v_where || v_condition || 'POD IN (''''''''||REPLACE(''' || :P30_POD || ''', CHR(13) || CHR(10), '','')||'''''''''')';
    v_condition := ' AND ';
    End If;
    But the query doesn't return any rows.
    I tried to reproduce it in Toad:
    select * from asx_worklistitem
    where
    POD IN (''''||REPLACE('541449200000171813'||CHR(13) || CHR(10)||'541449206006341366', CHR(13) || CHR(10), ''',''')||'''')
    ==> This is the query that does't return any rows
    select (''''||REPLACE('541449200000171813'||CHR(13) || CHR(10)||'541449206006341366', CHR(13) || CHR(10), ''',''')||'''')
    from dual;
    ==> This returns '541449200000171813','541449206006341366'
    select * from asx_worklistitem
    where pod in ('541449200000171813','541449206006341366');
    ==> and when I copy/paste this in the above query, it does return my rows.
    So why does my first query doesn't work?
    Doe anyone have any idea?
    Kind regards,
    Geert
    Message was edited by:
    Zorry

    Thanks for the help.
    I made it work, but via the following code:
    If (:P30_POD Is Not Null) Then
    v_pods := REPLACE(:P30_POD, CHR(13) || CHR(10));
    v_where := v_where || v_condition || 'POD IN (';
    v_counter := 1;
    WHILE (v_counter < LENGTH(v_pods)) LOOP
    v_pod := SUBSTR(v_pods, v_counter, 18);
    IF (v_counter <> 1) THEN
    v_where := v_where || ',';
    END IF;
    v_where := v_where || '''' || v_pod || '''';
    v_counter := v_counter + 18;
    END LOOP;
    v_where := v_where || ')';
    v_condition := ' AND ';
    End If;But now I want to make an update of all the records that correspond to this search criteria. I can give in a status via a dropdownlist and that I want to update all the records that correspond to one of these POD's with that status.
    For a region you can build an SQL query via PL/SQL, but for a process you only have a PL/SQL block. Is the only way to update all these records by making a loop and make an update for every POD that is specified.
    Because I think this will have a lot of overhead.
    I would like to make something like a multi row update in an updateable report, but I want to specify the status from somewhere else. Is this possible?

  • Is that Any Function Available

    Hi,
    I have the values like 00000000000988 in my table.
    Is that any Functions available in Oracle to trim the zero values in the first.
    so that i will get the field value as 988 alone.
    Thanks,
    Murali.V

    One other solution for 10G with Regex:
    Connected to Oracle Database 10g Enterprise Edition Release 10.1.0.2.0
    Connected as SYSADM
    SQL>
    SQL> SELECT t.a, regexp_replace(t.a, '^0*(.*)','\1') aaa
      2    FROM (
      3          SELECT '000000123' a
      4            FROM dual
      5          UNION
      6          SELECT '000000asdfawfd' a FROM dual) t
      7  ;
    A              AAA
    000000123      123
    000000asdfawfd asdfawfd
    SQL> And if it is obvious 0 only comes infront you can use TRANSLATE

  • I think I finished installing Mountain Lion, and am at the "log in" page with my name and the Lion icon, but I cannot do any of the functions on screen. That is, I cannot log in, sleep, restart, or shut down. I am running it on an Early 2009 Macbook Pro

    I think I finished installing Mountain Lion, and am at the "log in" page with the Mountain Lion icon, but I cannot do any of the functions on screen. That is, I cannot log in, sleep, restart, or shut down. I am running it on an Early 2009 Macbook Pro, which is said to have the capabilities of running Mountain Lion.

    BrettGoudy wrote:
    ...Is there any way I can install a partition that runs snow leopard on my early 2011 MB pro with what I have (new SSD, New RAM, Current version Lion running, no external drive, lack of original snow leopard disks [I lost them ] and the general 10.6.3 snow leopard boot disks)...
    As the last post suggests, call Apple and order a replacement original disc for about $17.  They will ask you the model and serial numbers.
    Your retail version of Snow Leopard OS 10.6.3 will not work on that Mac as it requires a minimum of OS X 10.6.7 to boot and operate.
    Another alternative is to again borrow another Mac to install your retail Snow Leopard into an external HD or partition, upgrade it to 10.6.8 and then clone it back to a partition on your MBP.

  • Any function in SQL or PL/SQL

    how the occurance-position of a particular character in a given string can be extracted with in a pl/sql block or procedure. is there any function available to do so.

    Maybe the INSTR function.
    See http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/functions55a.htm#SQLRF00651
    how the occurance-position of a particular character
    in a given string can be extracted with in a pl/sql
    block or procedure. is there any function available
    to do so.

  • Is there a similar function in Edge Animate that is similar to the draw path function in After Effects?

    Is there a similar function in Edge Animate that is similar to the draw path function in After Effects?

    No, I'm afraid not.  However, you can drop a clip from in to out into the timeline and the hit CMD+R and grab the end, changing the length of the clip to fit in the space that you need by speeding up the clip.
    Hope that helps.
    Andy

  • Is there any function module that brings out profile planner

    Hello experts,
    Is there any function module that brings out profile planner (I want to set planner profile as u201CSAP800u201D. I am using 7KE1 transaction.
    Example: I know, the FM - K_KOKRS_SET_BATCHINPUT will set the controlling area to 'CTIC' for the entire batch input process.
    Thanks in advance.

    look at these fms..
    CACS_PROFILE_PARTNER_READ
    CACS_PROFILE_SHOW

  • System table that stores info about any function module

    Hi All,
    I know that table TFDIR stores primary information about any function module.
    Could anyone tell me where the code of that function module gets stored in?
    Also.. If I want to write an ABAP code to read the function module code then what is the best possible solution?
    I want to read a function module code if that contains specific string.
    Can anyone help me  with that?
    Thanks in advace and any answer will be appreciated.
    Regards
    Jignesh
    Edited by: Jignesh Patel on Jun 12, 2008 12:22 PM

    Hi Jignseh,
    The codes are not stored in any table, they are stored as cluster.
    To read the code, you can use READ REPORT.
    But there you must provide the Include Name
    For Example , If you want to read the code of READ_TEXT,
    READ REPORT 'LSTXDU01'.
    You can get this include name inside include LSTXDUXX
    Use "GET_INCLUDES" to get all include names
    Edited by: Swastik Bharati on Jun 12, 2008 12:28 PM

  • Is there any function that returns the latest DDL statement

    can anyone tell me if there is any FUNCTION that returns latest DDL statement performed in a schema.
    OR
    if there is any TABLE that will be populated with latest
    DDL statement in schema.
    THANK YOU.

    The table all_objects (and/or dba_objects) contains a column called last_ddl_time. Thus, a query like
    scott@jcave > SELECT max(last_ddl_time)
      2  FROM all_objects
      3 WHERE owner = 'SCOTT';
    MAX(LAST_DDL_TI
    28-NOV-03will tell you the last time any object owned by SCOTT had DDL issued against it.
    Justin
    Distributed Database Consulting, Inc.
    www.ddbcinc.com/askDDBC

  • Is there any function module that generates date of 30th september of next

    is there any function module that generates date of 30th september of next year.?

    May be u mean...20100930
    You can simply
    Add 10000 to this years sept 30...If you want sept 30 from today...
    Data: G_DATE Type Sy-DATUM.
    G_DATE = Sy-DATUM.
    G_DATE+4(02) = '09'.
    G_DATE+6(02) = '30'.
    G_DATE0(04) = G_DATE0(04) + 1.
    Santhosh

  • I have recently upgraded to ios 7 on my iphone. I am currently at 7.0.2 which i installed yesterday. Now i notice that the keypad doesnt appear in any function under Phone. Keypad doesnt show up in contact search, or while adding new contacts or editing.

    I have recently upgraded to ios 7 on my iphone. I am currently at 7.0.2 which i installed yesterday. Now i notice that the keypad doesnt appear in any function under Phone. Keypad doesnt show up in contact search, or while adding new contacts or editing the existing. This is irritting.

    Try This...
    Close All Open Apps... Sign Out of your Account... Perform a Reset... Try again...
    Reset  ( No Data will be Lost )
    Press and hold the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears. Release the Buttons.
    http://support.apple.com/kb/ht1430

  • Is there any function that....

    Hello friends
          I wrote a ABAP program to print the PL (Part List). But while printing it jst takes 25 lines in the ckt refence else it don't print it. This is becoz of the reason that while printing it takes 1st ckt refence then 20 blank spaces then next ckt and so on. and it prints maximum of 500 characters. So if we have more than 25 lines we face problem. Is there any function that bypasses these 20 blank spaces and only consider the ckt refences. Plz help me in this. If possible sent me the code for it.
    Thnx
    Rakhi

    The table all_objects (and/or dba_objects) contains a column called last_ddl_time. Thus, a query like
    scott@jcave > SELECT max(last_ddl_time)
      2  FROM all_objects
      3 WHERE owner = 'SCOTT';
    MAX(LAST_DDL_TI
    28-NOV-03will tell you the last time any object owned by SCOTT had DDL issued against it.
    Justin
    Distributed Database Consulting, Inc.
    www.ddbcinc.com/askDDBC

Maybe you are looking for

  • Open file in finder

    Can someone help me with a really basic question about using Finder? I don't understand the keyboard shortcut shown in the File menu for 'Open' (or, maybe I understand but there is a problem). To me the keyboard shortcut shown for Open looks like an

  • I have updated my apple tv 2nd generation to the latest software but it shows the itunes symbol with the usb. Anyone know why this might be? Thanks

    I have updated my apple tv 2nd generation to the latest software but it shows the itunes symbol with the usb. Anyone know why this might be? Thanks

  • Passing values between forms

    Hi, I have a scenario where Form A invokes Form B (also passes some values while invoking) and goes to the background. After the user completes the operations on Form B it closes and I need to pass some values back to Form A. How do I pass the values

  • IDM 6 : Authorization Type in Rules

    Hi, With IDM 6, I am getting the following error while accessing a anonymous user task which uses custom rules as well as out of the box rules such as Regional Constants. ERROR: View access denied to Subject Reset on Configuration: Custom Alpha Numer

  • Hierarchy expansion in workbook

    Hi All, I've a workbook which has two queries based on same cost center hierarchy. When I refreshed the queries it added a new node to one of them which doesn't have any values and not in the other query. The hierarchy in the system has this new node