u2unidata

UniData Current Date Function


Is there the equivalent of the sql server getdate() function in UniData? I'd like to be able to query a table like this:

SELECT GETDATE() AS EXPORT_DATE, * FROM TABLE


Solution

  • There are two ways to do this - one that is more "standard", and another more flexible but slightly awkward.

    1) Create an I-descriptor that returns the current date like so:

    :AE DICT TABLE EXPORT_DATE
    001 I
    002 DATE()
    003 D4/
    004
    005 10R
    006 S
    

    And then

    :LIST TABLE EXPORT_DATE
    

    2) Using the Unidata "flavor" of the query language avoids creating a DICT item, but is sort of awkward to type and you need to be in ECLTYPE U (or use the command (list, sort) in lower case to force ECLTYPE U):

    :list TABLE EVAL "OCONV(DATE(),'D4/')" COL.HDG "EXPORT_DATE"
    

    Personally, I almost always have a TODAY, COUNTER, CURR.USER etc. DICT item in the main tables used for reporting. You can think of I-Descriptors as little mini-views from a SQL perspective, that only return one column. Here's an interesting set of examples on the possible date formats to return too.