Query to select value for max date from a varchar field containing year and month

I'm having trouble selecting a value from a table that contain a varchar column in YYYY-MM format. 
ex.
Emp_id Date Cost
10264 2013-01 5.00
33644 2013-12 84.00
10264 2013-02 12.00
33644 2012-01 680.0
59842 2014-05 57.00
In the sample data above, I would like to be able to select the for each Emp_id by the max date. Ex. For Emp_id 10264, the cost should be 12.00.

create table test (Emp_id int, Date varchar(10), Cost decimal (6,2))
insert into test values(
10264, '2013-01', 5.00 ),
(33644, '2013-12', 84.00 ),
(10264, '2013-02', 12.00 ),
(33644, '2012-01', 680.0 ),
(59842, '2014-05', 57.00 )
Select Emp_id,[Date],Cost FROM (
select *,row_number() Over(Partition by Emp_id Order by Cast([Date]+'-1' as Datetime) Desc) rn
from test)
t
WHERE rn=1
drop table test

Similar Messages

  • Is there any deffirence for master data from flat fime bi 7.0 and 3.5?

    hi friends,
    is there any deffirence for master data from flat fime bi 7.0 and 3.5?
    regards
    suneel.

    you can follow the same 3.x dataflow eventhough u upgrade.
    the only diff
    3.x - would be emulated DS
    7.0 - RSDS
    3.x - file path declared in infopack
    7.0 - is declared in DS (that would be inherted by infopack)
    Infosource - optional - works fine on both the versions
    creating a new DS, it has to be RSDS .. no way out

  • Query in selected value for radiogroup

    Is it possible to have a query in the p_selected_value of an htmldb_item.radiogroup ?
    If yes, how ?
    If not, is it possible to always set the first radio button as the selected value ?
    thx,
    Patrick

    Hi Enric,
    After the execution of a query using Query designer, after the selection of the variable values, you will get navigation block and the data beside that in Data Analysis tab. In this navigation block, you will find only the restricted values after the variable selection. You will not find the values selected displayed over there. When you select a chracteristic and click on filter button, you will get the values which are restricted only within the data displayed beside that in the output.
    If you want to have a look at the variable selection parameter that you have selected in the popup, you should go to Information tab and you can check the same there.
    The Navigation Pane Web item shows the navigational state of a data provider. All the characteristics and structures of the data provider are listed. You can alter the navigation status by using drag and drop to drag characteristics or structures to an axis (rows or columns) of the table, or to remove them from the axis. Using drag and drop, you can swap the axes in the navigation area; the table changes accordingly. You can also drag characteristics to the filter pane using drag and drop.
    Hope this helps u...
    Regards,
    KK.

  • Hide all members' value for specify date from CUBE level

    Hi There,<o:p></o:p>
    With my current CUBE data available for yesterday, but 2-5 % data also get loaded through ETL for today as it's live data feed and process all data
    at CUBE level.<o:p></o:p>
    Now problem here till yesterday all data are okay and that make send to end user, but chunk of data for today (2-5 %) don’t make any sense…. now question
    here is any way I can hide value for all members for today which is (2-5 %) only, that way data visible from CUBE level only till yesterday.<o:p></o:p>
    Exactly what I mean if anyone connect to my CUBE they can only see data till yesterday (day-1), but not for today.<o:p></o:p>
    Regards,<o:p></o:p>
    Nagen<o:p></o:p>
    Thanks, Nagen

    Hi,
    two possibilities:
    1) Create a security implementation, so that the users are allowed to see the data until yesterday. Dimension Security on your Date Dimension)
    2) Scope the Dimension Member for future Dates to NULL
    Kr Jürgen

  • Options for loading data from legacy mainframe to SAP CRM and ECC

    Hello All,
    I am new to SAP.
    As part of data conversion planning from legacy mainframe to SAP CRM and ECC systems, I need to know the different tools available for loading the data and comparative analysis of the tools by showing the features. Please also describe the process to evaluate the tools (prototyping, technical discussions etc) and make the recommendations.
    I would also appreciate any information on testing tools like (eCATT) and any third party tools (like Informatica)
    I know I am asking for lot of things here. But, I really appreciate any information reagrding this.
    Thanks,
    Balu

    Hi
    Data Migration(Conversions) mainly involves the following Major Steps
    Discovery->Extract->Cleanse->Transform->Load
    Discovery-> Involves identifying various source systems available where the actual data is residing.
    Extract->Extract the data from the source systems(legacy systems)
    Cleanse->Cleanse the data by enriching it,De-duplications etc
    Transform->Transform the data into SAP Loadable format
    Load->Upload the data into SAP Using the Load Programs(Eg,BDC,LSMW,Data Transfer Workbench,BAPIs etc)
    Also i would request you to visit http://www.businessobjects.com/solutions/im/data_migration.asp
    Cheers,
    Hakim

  • Select max date from a table with multiple records

    I need help writing an SQL to select max date from a table with multiple records.
    Here's the scenario. There are multiple SA_IDs repeated with various EFFDT (dates). I want to retrieve the most recent effective date so that the SA_ID is unique. Looks simple, but I can't figure this out. Please help.
    SA_ID CHAR_TYPE_CD EFFDT CHAR_VAL
    0000651005 BASE 15-AUG-07 YES
    0000651005 BASE 13-NOV-09 NO
    0010973671 BASE 20-MAR-08 YES
    0010973671 BASE 18-JUN-10 NO

    Hi,
    Welcome to the forum!
    Whenever you have a question, post a little sample data in a form that people can use to re-create the problem and test their ideas.
    For example:
    CREATE TABLE     table_x
    (     sa_id          NUMBER (10)
    ,     char_type     VARCHAR2 (10)
    ,     effdt          DATE
    ,     char_val     VARCHAR2 (10)
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0000651005, 'BASE',    TO_DATE ('15-AUG-2007', 'DD-MON-YYYY'), 'YES');
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0000651005, 'BASE',    TO_DATE ('13-NOV-2009', 'DD-MON-YYYY'), 'NO');
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0010973671, 'BASE',    TO_DATE ('20-MAR-2008', 'DD-MON-YYYY'), 'YES');
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0010973671, 'BASE',    TO_DATE ('18-JUN-2010', 'DD-MON-YYYY'), 'NO');
    COMMIT;Also, post the results that you want from that data. I'm not certain, but I think you want these results:
    `    SA_ID LAST_EFFD
        651005 13-NOV-09
      10973671 18-JUN-10That is, the latest effdt for each distinct sa_id.
    Here's how to get those results:
    SELECT    sa_id
    ,         MAX (effdt)    AS last_effdt
    FROM      table_x
    GROUP BY  sa_id
    ;

  • Query - select values for variables form list / Bex 7

    Hello together,
    when I open a query in the 'Business Explorer Analyzer 7' and I want to select the values for my variables from list, BW shows always the values from history. 
    Is it possible to change this? I want to see always the single values.
    Thanks and best regards.
    Jörg

    Hello Jörg
    The variable values in history are shown in drill down button of variable input box, whereas a button beside it will show a list of values when clicked. These are F4 value help selections.
    How is variable created? Please create variable with basic settings as
    'single value'.
    Regards,
    Asit Ramteke

  • Issue for retrive data from ITAB

    Case:HOW CAN WE FETCH DATA FROM TRANSPARENT TABLE
    scenario:calculating net price for material on sales order
    (on the basis of material number,sales organization,distribution channel,division,sale to partY ,sales office)
    For this 5 prices are calculated :
    a)zmrp
    b)zlbj
    c)zmlb
    d)zdij
    e)mwst
    A bapi is developed through which all these data are fetched using joins on transparent and pooled tables.
    Bapi is properly working in Sap Environment.But when fetching data from non sap environment(.NET) only pooled tables are returning data.
    Transparent tables are returning blank data.
    And also if in query of transprent table if  in " where Clause " all parameters are hard codded then transparent table also return data in non sap envirnment.
    for eg...
    instead of writing ---
    select data from tranparent table where matnr= (matnr variable made in bapi entered by user) and vkorg=(sales org  variable made in bapi) ....same with all conditions
    if we write(returing data)----
    select data from tranparent table where matnr='5476665987' and vkorg='1400' ....same with all conditions
                                                                                    FUNCTION ZBAPI_BAR3.
    ""Local Interface:
    *"  IMPORTING
    *"     VALUE(MATNR) TYPE  ZBAPI_IMPORT2-MATNR
    *"     VALUE(VKORG) TYPE  ZBAPI_IMPORT2-VKORG
    *"     VALUE(VTWEG) TYPE  ZBAPI_IMPORT2-VTWEG
    *"     VALUE(KUNNR) TYPE  ZBAPI_IMPORT2-KUNNR
    *"     VALUE(SPART) TYPE  ZBAPI_IMPORT2-SPART
    *"     VALUE(AUART) TYPE  ZBAPI_IMPORT2-AUART
    *"     VALUE(VKBUR) TYPE  ZBAPI_IMPORT2-VKBUR
    *"  EXPORTING
    *"     VALUE(RETURN) TYPE  BAPIRETURN
    *"  TABLES
    *"      ITAB STRUCTURE  ZBAPI_TABLE3
      DATA: LAND1  LIKE KNA1-LAND1  ,
            REGIO  LIKE KNA1-REGIO  ,
            WERKS  LIKE VBAP-WERKS  ,
           KNUMH  LIKE A004-KNUMH  ,
                   KNUMH LIKE ZBAPI_TABLE3-Knumh  ,
            KBETR   LIKE  COND_KONW-Kbetr ,
           LIKE ZBAPI_TABLE3-KBETR  ,
          KNUMH1(10) TYPE C ,
                KNUMH2(10) TYPE C ,
                KNUMH3(6) TYPE C ,
         KNUMH2 LIKE ZBAPI_TABLE3-KNUMH  ,
         KNUMH3 LIKE ZBAPI_TABLE3-KNUMH  ,
         KNUMV LIKE  ZBAPI_TABLE3-KNUMV  ,
            KDGRP  LIKE KNVV-KDGRP  ,
            TAXKD  LIKE KNVI-TAXKD  ,
            TAXM1  LIKE MLAN-TAXM1  ,
            ADRNR  LIKE TVBUR-ADRNR ,
            REGION LIKE ADRC-REGION ,
            DATE  TYPE A503-DATAB .
      SELECT SINGLE KDGRP FROM KNVV INTO KDGRP WHERE KUNNR  = KUNNR AND VKORG = VKORG AND VTWEG = VTWEG AND SPART = SPART   .
      SELECT SINGLE LAND1 REGIO  FROM KNA1 INTO (LAND1,REGIO)  WHERE KUNNR  = KUNNR .
      SELECT SINGLE WERKS FROM VBAP INNER JOIN VBAK ON VBAPVBELN = VBAKVBELN  INTO WERKS  WHERE AUART = AUART  .
      SELECT SINGLE TAXKD FROM KNVI INTO TAXKD WHERE KUNNR = KUNNR AND ALAND = LAND1 AND TATYP = 'MWST' .
      SELECT SINGLE TAXM1 FROM MLAN INTO TAXM1 WHERE MATNR = MATNR AND ALAND = LAND1  .
      SELECT SINGLE ADRNR FROM TVBUR INTO ADRNR WHERE VKBUR = VKBUR  .
      SELECT SINGLE REGION FROM ADRC INTO REGION WHERE ADDRNUMBER = ADRNR   .
      DATE = SY-DATUM .
      SELECT SINGLE KNUMH FROM A931 INTO KNUMH1 WHERE KAPPL = 'V' AND KSCHL = 'ZMRP' AND VKORG = VKORG AND VTWEG = VTWEG AND WERKS = '1410' AND KUNNR = KUNNR AND MATNR = MATNR AND KFRST = SPACE AND DATAB LE DATE AND DATBI GE DATE  .
    SELECT SINGLE KNUMH FROM A931 INTO KNUMH1 WHERE KAPPL = 'V' AND KSCHL = 'ZMRP' AND VKORG = '1400' AND VTWEG = '10' AND WERKS = '1410' AND KUNNR = '0000100163' AND MATNR = 'A10AN027PNSL' AND KFRST = SPACE AND DATAB LE DATE AND DATBI GE DATE  .
      SELECT SINGLE zkarigar FROM zkari INTO KNUMH1 WHERE erdat = '20070410' .
    SELECT SINGLE KNUMH FROM A004 INTO KNUMH1 WHERE KAPPL = 'V' AND KSCHL = 'ZMRP' AND VKORG = VKORG AND VTWEG = VTWEG AND MATNR = MATNR  AND DATAB LE DATE AND DATBI GE DATE  .
    *'0000280050'
    CLEAR KNUMH .
    CLEAR KBETR .
    SELECT SINGLE KNUMH FROM A503 INTO KNUMH1 WHERE KAPPL = 'V' AND KSCHL = 'MWST' AND ALAND = LAND1 AND WKREG = REGION AND REGIO = REGIO
    AND TAXK1 = TAXKD  AND TAXM1 = TAXM1 AND KFRST = SPACE  AND DATAB LE DATE AND DATBI GE DATE and knumh = '0000279708'.
    concatenate '0000' KNUMH into knumh1 .
    **KNUMH1 = KNUMH .
    **select single kbetr from konp into kbetr where knumh = knumh1 .
    **knumh3 = knumh1+4(6) .
    ***itab-kbetr = kbetr .
    **concatenate '0000' knumh3 into knumh2 .
    **write:/ knumh2 .
    ITAB-KNUMH1 =  KNUMH2 .
    ITAB-KNUMH1 = KNUMH1 .
      APPEND ITAB .
    *loop at itab .
    *write:/ itab-knumh1 .
    *endloop .
    CLEAR KNUMH .
    CLEAR KBETR .
      SELECT SINGLE KNUMH FROM A940 INTO KNUMH WHERE KAPPL = 'V' AND KSCHL = 'ZDIJ' AND VKORG = VKORG AND VTWEG = VTWEG AND KDGRP = KDGRP AND MATNR = MATNR AND KFRST = SPACE AND DATAB LE DATE AND DATBI GE DATE .
      SELECT SINGLE KNUMH FROM A931 INTO KNUMH WHERE KAPPL = 'V' AND KSCHL = 'ZDIJ' AND VKORG = VKORG AND VTWEG = VTWEG AND WERKS = WERKS AND KUNNR = KUNNR AND MATNR = MATNR AND KFRST = SPACE AND DATAB LE DATE AND DATBI GE DATE  .
    ITAB-KNUMH =  KNUMH.
    APPEND ITAB .
    CLEAR KNUMH .
    CLEAR KBETR .
    ITAB-KNUMH =  KNUMH .
    APPEND ITAB .
    COMMIT WORK AND WAIT.
    ENDFUNCTION.
    Thanks & Regards
    Amrish

    Hi,
    Please Check this => The specified item was not found.
    How to post code in SCN, and some things NOT to do...
    Faisal

  • Is there any way we can set default value for a Date Attribute to current date in Master Data Services

    Is there any way we can set default value for a Date Attribute to current date in Master Data Services.
    I as well wants to know that is there any posibility to show Calendar control while input data into respective date attributes.
    Thanks.

    Hi Anagha,
    So far i havent found any way to set todays date by default from MMI, but i guess this flow should work as workaroud
    1. Add buisness rule which can set a default value when Date = NULL/Blank
    2.get the entity table ,use -select EntityTable from mdm.tblEntity where Name = '<enter entity name>'
    3.Go to that table and add a after update trigger like
    if uda_<entityid>_<attributeid(Date attribute)> = default value
    update uda_<entityid>_<attributeid(Date attribute)> =getdate() where id = <LastUpdatedRow>
    I will check on this too from my side.
    By the way AFAIK i dont think so calendar control integration is possible .

  • Abort Could not determine a value for variable 0DAT from the authorizations

    Hi All,
    I encountered an error '/ Abort Could not determine a value for variable 0DAT from the authorizations\' when executing my query on a multiprovider in BW 3.5.
    Can anyone help me in finding a solutionn to this issue.
    Thanks,
    Kartik.

    Hi Kartik,
    I am sorry as that note is for NW2004s. Please check if 0DAT variable installed from a business content? if not then I think thats the cause of the problem.
    Hope this helps,
    Bye...

  • Good for processing data from a web application?

    It seems like all the examples provided for ASA are about processing data streaming in from IoT or mobile apps. Is ASA appropriate for processing data from websites? For example, I have a multi-tenant web API and I need to roll up usage and calculate billing
    for my clients. My clients can upload resources with me which I store in blob storage. But blob storage gives me no way of knowing how many resources have been uploaded and how long I have stored them. Would ASA be a good fit for calculating these figures?

    I have solved this task in folowing way:
    I have add ADF read only form to my page (which I need anyway). The form displays data selected in the graph (using another VO, which is linked to graph VO). Command button calls my managed bean, which handles the data via the bindings executables (view iterators).

  • Getting an error while activating a planning area "Enter values for planning horizon From and planning horizon To for the storage time profile level"

    Dear S&OP community,
    I am getting following error while creating a planning ares in a newly installed sandbox. "Enter values for planning horizon From and planning horizon To for the storage time profile level".
    This what I did...
    1) Created new attributes and master data objects and activated them successfully.
    2) Time profile created and activated successfully
    3) Trying to create planing area by assigning  time profile in step 2 and assigned master data from step1..Unable to save the data and system returns 
    this error - "Enter values for planning horizon From and planning horizon To for the storage time profile level"
    My understanding is time profile needs to be active  but doesn't have to have values...
    Any help is appreciated.
    Thanks,
    Krishna

    YS,
    Here are my time profile settings
    Level       Name          Display Horizon - Past  Display Horizon - Future
    1             Monthly     -6                                       11         
    2             Quarterly     -2                                       3
    3             Yearly        -1                                       2
    Time profile is active and but time profile data is not loaded
    Thanks,
    Krishna

  • Set Default Value for a Date Navigator

    Hi all
    Is it possible to set a default value for a date navigator.I mean with out picking the date from the Navigator, on load of the view itself i need a particualr date to be displayed (say 12/31/2000).
    Thanks in advance

    Hi,
      create a value attribute of type date bind to the input field and in wdInit()of view controller write this code..
      wdContext.currentContextElement().setValueAttrName(new Date(Calendar.getInstance().getTimeInMillis()));
    means ...
    u r setting the date entered into some context ....
    type of that attribute must be of date and for initial value write the above code ..if it is under node element create nodeelement bind it to context and write the code accordingly..
    Message was edited by: Yashpal Gupta

  • Is there any VIEW or FM for pulling data from VBAK, VBAP?also for VBEP,VBBE

    Hi Experts,
    1) Instaed of using JOINS and FOR ALL ENTRIES, am looking to use any view or FM for pullinmg the data from, VBAK & VBAP,
    So, pls let me knwo that, Is there any VIEW or FM for pulling the data from the above  of tables
    2) Instaed of using JOINS and FOR ALL ENTRIES, am looking to use any view or FM for pullinmg the data from, VBEP & VBBE,
    So, pls let me knwo that, Is there any VIEW or FM for pulling the data from the above  of tables
    3) Am guessing FOR ALL ENTRIES is better than JOINS in PERFORMENCE perspective, Is am I correct?
    thanq
    Edited by: Srinivas on May 9, 2008 5:36 PM

    Hi Srinivas,
    You can use the view WB2_V_VBAK_VBAP2 for fetching data from VBAK and VBAP instead of using a JOIN. Note that, in the view, item data fields will have a I following the field name (POSNRI, MATNR_I are the item data fields from VBAP). The master data fields of VBAK are the same.
    As far as i know, there are no standard views provided by SAP for VBEP and VBBE. Not sure if FM exists either.
    While using FOR ALL ENTRIES clause make sure that you specify the entire primary key (EX. if selecting from VBAP specify VBELN and POSNR) as fields for selection or in the selection criteria. Its much better if you have the primary key in both. This is really important because without specifying the entire key and using FOR ALL ENTRIES will drastically bring down the performance. And also, If you are fetching not more than 100 or 200 entries using the clause it is fine, beyond that its same as using a select statement within LOOP...ENDLOOP.
    So, you have to decide whether to use FOR ALL ENTRIES or a JOIN while selecting data depending on the requirement. If you don't have the entire key either in fields for selection or selection criteria, then its better to use a JOIN or VIEW.
    The following is an example for using FOR ALL ENTRIES clause effectively.
             Select VBELN
                        POSNR
                        MATNR
                From VBAP
                  into Table T_VBAP
              For All Entries in T_DATA
              Where VBELN eq T_DATA-VBELN
                  And POSNR eq T_DATA-POSNR.
    I hope this helps, Please let me know if you need further assistance.

  • Storing multipl values for meta data in DOCUMENT_META_DATA

    Hi,
    We currently have 3 content types in our system: news, announcements, and events.
    They are currently stored in 3 different tables. We want to make this content
    available via the various CM (select) and PZ tags (contentquery, contentselector).
    I'd like to avoid writing my own doc provider (file:///D:/bea7/weblogic700/wlp/docs70/dev/conmgmt.htm#999019)
    and instead would like to begin to publish document data directly to the reference
    implementation tables (DOCUMENT and DOCUMENT_METADATA).
    It seems like I should be able to do that with one exception. It doesn't seem
    like we can store multiple values for meta data attributes. If you take the out
    of the box p13n example, a lot of the data is tagged with 'genre' = Something
    (i.e. Rock, Hip-hop, etc). Then content queries use this genre to personalize
    pages.
    What if I have a band that has multiple genres? What if I want to tag my band
    as Rock and Hip-hop? And then also want that band to appear on both a Rock lovers
    and a Hip hop groupies page? Is this possible with the default implementation?
    I know when I tried entering multiple 'genre' meta data values for a same document
    ID, it gave me a PK constraint violation. Any other trick around this?
    Thanks,
    Will Young
    ps. using weblogic 7...

    Yes Subler http://code.google.com/p/subler/ does support adding the HD tag.
    On the Mac I wouldn't use anything but Subler for tagging, best UI, best metadata lookup, best underlying libraries for mp4 files (I'm biased on the libraries part).
    Cheers Ed.

Maybe you are looking for

  • Upload Open Purchase orders

    Hi All, Our client is implementing SRM and the conversion is  from non-sap legacy system. Is there a way to upload all the Open PO's without manually keying it in. Thanks, Reena

  • Problem with function arguments

    I am having a problem with arguments to a function not working. In the attached example, the values passed to the function are never reflected within the function. Can any one tell me what I am doing wrong? Thanks, David

  • A question about charging...

    When I have my shuffle plugged in long enough for the green light to come on, signifying that it is fully charged I then remove it, but when I plug it back in, the light is orange again, even if it is mere minutes later. Any help would be appreciated

  • How many sessions does SAP allow you to have ??

    Dear Memebers, How many sessions does SAP allow you to have ?? a) 3 b) 6 c) 9 d) 12. I guess the right answer is B and C but in choices I have to select only 1, which answer will you pick and Why ?? Thank You. Madhu.

  • Separate Display Quantizations for the same part in Notation

    I'm having a hard time with something that seems like it would be easy to fix. How can I set up a part in the notation editor and use one display quantization setting for say, bars 3 and 4, and another display quantization setting for bars 5 and 6. (