How to fill empty cells with previous non empty value?

Hello 
rows where cat=2 do not have price and i want to fill it with previous value wich cat=1 for every item
Table named tb
id        item_no     price         cat 
1           I1             5           1
3           I1                          2          the price must be 5   
4           I1                          2          the price must be 5  too
9           I1             2           1
10         I2             10          1
11         I2             5           1
15         I2              10        1       
28         I2                          2        the price must be 10  
30         I2             2           1
32         I2             10          1
filled table must be like that:
id        item_no     price       cat 
1           I1             5           1
3           I1            
5           2          
4           I1            
5          2          
9           I1             2          1
10         I2             10        1
11         I2             5          1
15         I2             10        1       
28         I2            
10        2      
30         I2             2          1
32         I2             10         1
How can i do that?

Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. You have no idea,
do you? Temporal data should use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
This is minimal polite behavior on SQL forums. Why are you so rude to people? Now we have to guess a everything and try to fix your mess. 
There is no generic “id” in RDBMS; it has to be an industry identifier or “<something in particular>_id”. I like the GTIN. Was that useless vague name supposed to be “<something>_cat” as a category scale? 
CREATE TABLE Items
(foo_seq INTEGER NOT NULL, 
 gtin CHAR(15) NOT NULL, 
 unit_price DECIMAL (12,2), 
 foobar_cat CHAR(1) NOT NULL
     CHECK (foobar_cat IN ('1', '2')), 
CREATE PROCEDURE Add_New_Item
INSERT INTO Items
VALUES
(1, 'I2', 5.00, 1), 
(3, 'I1', NULL, 2), -- unit price must be 5.00
(4, 'I1', NULL, 2), -- unit price must be 5.00
(9, 'I1', 2.00, 1), 
(10, 'I2', 10.00, 1), 
(11, 'I2', 5.00, 1), 
(15, 'I2', 10.00, 1), 
(28, 'I2', NULL, 2), -- unit price must be 10
(30, 'I2', 2.00, 1);
>> rows where cat=2 do not have price and I want to fill it with previous value which cat=1 for every item <<
Rows in a table are not ordered! There is no concept of “previous row” in RDBMS. This is fundamental. Are you using a sequence that you erroneously call “id”? 
But that makes no sense! Look at (1, 'I2', 5.00, 1) and then (3, 'I1', NULL, 2). Why does item 'I2' have anything to do with the price of item 'I1'? 
Can you explain? 
Table named tb
id   item_no   price   cat 
1    'I1',  5    1
3    'I1',  NULL   2  -- the price must be 5   
4    'I1',  NULL   2  -- the price must be 5  too
9    'I1',  2    1
10   'I2',  10   1
11   'I2',  5    1
15   'I2',   10   1   
28   'I2',  NULL   2   -- the price must be 10  
30   'I2',  2    1
32   'I2',  10   1
filled table must be like that:
id   item_no   price   cat 
1    'I1',  5    1
3    'I1',  5    2   
4    'I1',  5   2   
9    'I1',  2   1
10   'I2',  10   1
11   'I2',  5   1
15   'I2',  10   1   
28   'I2',  10   2   
30   'I2',  2   1
32   'I2',  10   1
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL

Similar Messages

  • Plot empty point in line chart with previous non empty value

    Hello,
    I have a problem to plot series data in SSRS line chart, with the empty point, I don't want use average and zero provided by the report builder, I want use the last non empty data to fill the empty point, tried to use expression =Previous(Field!Value), no
    luck, any one have some good idea?
    P.S. do not want to use query to fill the null with previous non null value, just from the performance point view. at last , the chart should have some line as square wave with different height, if I use average for empty point, it shows slop wave line which
    is not reflect the real production.
    Thanks
    Richard 

    Hi Richard,
    In Reporting Services, if the chart type is a linear chart type (bar, column, scatter, line, area, range), null values are shown on the chart as empty spaces or gaps between data points in a series. By default, empty points are calculated by taking the average
    of the previous and next data points that are not null.
    If we want to use previous value to replace the empty value, please refer to the following steps:
    Right-click the field which displayed in Y axis (Height) to open the Series Properties.
    In the Value field to modify the expression to look like this:
    =iif(isnothing(Sum(Fields!Height.Value)),previous(sum(Fields!Height.Value)),sum(Fields!Height.Value))
    The following screenshot is for your reference:
    If there are any other questions, please feel free to ask.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Fill BEx Variable with more than one value via Custom Exit

    Dear SDN comunity,
    I want to fill a BEx Variable via a custom exit. My problem is, I don't know how to fill this variable with more than one value.
    I try to give you some background info based on an exaple:
    <u><b>Variable-Details</b></u>
    <b>Type of Variable:</b> Characteristic Value
    <b>Variable Name:</b> ZCCD
    <b>Description:</b> Company Code Selection
    <b>Processing by:</b> Custom Exit
    <b>Characteristic:</b> Company Code
    <b>Variable Represents:</b> Multiple Single Values
    <u><b>This is the used ABAP code:</b></u>
    WHEN 'ZCCD'.
    CLEAR l_s_range.
    l_s_range-low = '2002;2004'.
    l_s_range-sign = 'I'.
    l_s_range-sign = 'EQ'.
    APPEND l_s_range TO e_t_range.
    <u><b>The system returns this message:</b></u>
    Value "2002;2004" is too long for variable ZCCD
    appreciate your help!
    //michael

    Eugene, Marcus
    it works now, thx a lot!
    Please find attached the final code:
    CLEAR l_s_range.
    l_s_range-low = '2002'.
    l_s_range-sign = 'I'.
    l_s_range-<b>opt</b> = 'EQ'.
    APPEND l_s_range TO e_t_range.
    CLEAR l_s_range.
    l_s_range-low = '2004'.
    l_s_range-sign = 'I'.
    l_s_range-<b>opt</b> = 'EQ'.
    APPEND l_s_range TO e_t_range.
    (Delta to Marcus's code is bold)

  • Numbers: how do I turn on the feature that fills the cell with typing that was previously used? The previous version had this feature. I could type the first letters of a name in a cell and the entire name would automatically appear.

    Numbers: how do I turn on the feature that fills the cell with typing. In the previous versions, I could type a name or word and then a list of names/words with the same letters would appear. I could choose the name/word to enter into the cell. This saved many strokes. If I was typing a word with only one like it previously entered, that word would appear, grayed, and I could simply tab to the next cell, automatically entering that word in that cell. Is this feature in this version of Numbers? The autofill tab 1)I can't turn it on and 2) it doesn't seem to do the same thing.
    Thanks.

    The developers failed to propagate that feature from version 2 to version 3. I believe it is on the short list of things to be restored in May 2014 or so.
    Here's the full list as published by Apple:
    Numbers
    Customize toolbar
    Improvements to zoom and window placement
    Multi-column and range sort
    Auto-complete text in cells
    Page headers and footers
    Improvements to AppleScript support
    Jerry

  • Fill empty cell with '0'

    Hi,
    I have a crosstab table and some of the cells within the table are empty purely because there is no data in the database which is reasonable.
    For presenation purposes, what are my options to fill these empty cells with '0'?
    I was hoping to find an option to default empty cells to '0', but failed to find such feature.
    Thanks in advance.
    Regards
    Tom

    Hi Tom
    Steps to fill empty cell with '0':-
    1. Select intersection cell in cross tab.
    2. Go to properties tab.
    3. In Text Format section, click on Number Format button.
    4. Select Format type is 'Number' and check the Custom check box.
    5. Enter 0 in all text boxes(Positive, Negative, Equal to zero, and Undefined).
    6. Click ok.
    Now you can see 0 in the Emply cells of cross tab.
    If you want decimal values, enter 0.00 in Positive box.

  • Iam using a table in numbers to plot daily graph lines. If I fill a cell with a text box  at say zero it plots the graph. I can't actually set the cell value until the actual day but the graph plots it at zero when I don't want it to plot anything. Is tho

    I am using a table in Numbers to plot daily graph lines. Mood swings of how I am on the day, i"m a depressive.
    If I fill a cell with a step box at say zero it plots the graph. I can't actually set the cell value until the actual day but the graph plots it at zero when I don't want it to plot anything. Is there a work around. so thatbgraph only plots on the day?

    The answer is (sort of) in your subject, but edited out of the problem statement in the body of your message.
    When you use a stepper or a slider, the value in the cell is always numeric, and is always placed on the chart if that cell is included in the range graphed by the chart.
    But if you use a pop-up menu cell, you can specify numeric or text values in the list of choices for in the menu. Numeric values will be shown on the chart. Text values will not.
    For the example, the values list for the pop-up menu was:
    5
    3
    1
    Choose
    -1
    -3
    -5
    The first pop-up was set to display Choose, then the cell was filled down the rest of the column. Any text value (including a single space, if you want the cell to appear blank) may be used instead of Choose.
    For charts with negative Y values, the X axis will not automatically appear at Y=0. If your value set will include negative values, I would suggest setting the Y axis maximum and minimum to the maximum and minimum values on your menu list, rather than letting Numbers decide what range to include on the chart. Place a line shape across the chart at the zero level, and choose to NOT show the X axis.
    Regards,
    Barry

  • How to fill a symbol with color

    How to fill a symbol with color?

    Good day!
    What do you mean by »symbol« in this case?
    Is this on a Layer of its own or is it part of a photograph?
    Could you please post a screenshot with the Layers Panel visible?
    Regards,
    Pfaffenbichler

  • I HOW I FILL PDF FORM WITH HEBROW ON CHROME ?

    I HOW I FILL PDF FORM WITH HEBROW ON CHROME ?

    Chrome uses its own (incompatible) PDF viewer.
    Download the PDF to your local disk, then fill it from there with Adobe Reader.  Or use a browser that uses the Adobe PDF plugin.

  • Previous non empty value

    Hi,
    I have a situation where I have to update the previous non empty date until there is non empty value. Then use the next non empty value. Data is sorted on group id.
    for example I am creating new field which update the date column which just for example:
    it would be great if there is way to implement using set operation not through cursor.
    thanks in advance
    Zaim Raza
    http://zaimraza.wordpress.com/

    CREATE TABLE #C (X CHAR(1) ,Y INT)
    INSERT INTO #C values(NULL, 1)
    INSERT INTO #C values(NULL, 2)
    INSERT INTO #C values(NULL, 3)
    INSERT INTO #C values('A', 4)
    INSERT INTO #C values(NULL, 1)
    INSERT INTO #C values(NULL, 2)
    INSERT INTO #C values('B', 3)
    SELECT * FROM #C
    ALTER TABLE #C ADD ID INT IDENTITY(1,1)
    SELECT CASE WHEN X is not null
                THEN X
                ELSE (SELECT MIN(X)
                      FROM #C
                      WHERE ID >= t.ID)
           END AS X,
           Y
    FROM #C t
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How to share a project with a non-Adobe user and present it to prospect customers?

    I Have to share my project with a person who will present it to prospect customers. I cannot ask this person to open an Adobe account. Is there a way for him to access my DPS folio and show it? Or can I export it in a way that allows to appreciate the interaction features built inside?
    Thanks!

    OK, got it. Thank you!
    2015-01-17 14:46 GMT+01:00 Bob Levine <[email protected]>:
        How to share a project with a non-Adobe user and present it to
    prospect customers?  created by Bob Levine
    <https://forums.adobe.com/people/BobLevine> in Digital Publishing Suite
    - View the full discussion
    <https://forums.adobe.com/message/7105349#7105349>

  • How to fill internal table with selection screen field.

    Hi all,
    i am new to sap . pls tell me how to fill internal table with selection screen field.

    Hi,
    Please see the example below:-
    I have used both select-options and parameter on the selection-screen.
    Understand the same.
    * type declaration
    TYPES: BEGIN OF t_matnr,
            matnr TYPE matnr,
           END OF t_matnr,
           BEGIN OF t_vbeln,
             vbeln TYPE vbeln,
           END OF t_vbeln.
    * internal table declaration
    DATA : it_mara  TYPE STANDARD TABLE OF t_matnr,
           it_vbeln TYPE STANDARD TABLE OF t_vbeln.
    * workarea declaration
    DATA : wa_mara  TYPE t_matnr,
           wa_vbeln TYPE t_vbeln.
    * selection-screen field
    SELECTION-SCREEN: BEGIN OF BLOCK b1.
    PARAMETERS : p_matnr TYPE matnr.
    SELECT-OPTIONS : s_vbeln FOR wa_vbeln-vbeln.
    SELECTION-SCREEN: END OF BLOCK b1.
    START-OF-SELECTION.
    * I am adding parameter value to my internal table
      wa_mara-matnr = p_matnr.
      APPEND wa_mara TO it_mara.
    * I am adding select-options value to an internal table
      LOOP AT s_vbeln.
        wa_vbeln-vbeln =  s_vbeln-low.
        APPEND  wa_vbeln TO  it_vbeln.
      ENDLOOP.
    Regards,
    Ankur Parab

  • How to use NODIM func with out it's values being rounded

    I created a new calculated key figure in Query Designer 3.x, and used the function NODIM() - Value with out dimensions. When I use this function, the values are rounding off to the nearest value.
    For example, I have a value 0.000075 US$, when I use NODIM function the value is displayed as 0.000080. Value is getting rounded to nearest value.
    I tried using absolute value it did not work.
    Can any one tell me how to use NODIM function with out it's value being rounded to nearest value.
    Thanks,

    Hi,
    According to your description, you might want that "Notice" field has a default value when form is created and users can be able to change the value of that
    field.
    As a workaround, you can add an action rule in “Name” field via InfoPath to fill the default value in “Notice” field only when “Name” field is not blank and “Notice”
    field is blank.
    Settings of the rule are as below, you can modify it based on your need:
    Here is a link about how to add an action rule in InfoPath form, you can use it as a reference:
    https://support.office.microsoft.com/en-us/article/Add-rules-for-performing-other-actions-5322d726-b787-4e5f-8d37-ba6db68b451d?CorrelationId=8a64c12f-aa60-4d90-b1f9-a44fcc4e74b5&ui=en-US&rs=en-US&ad=US
    Best regards
    Patrick Liang
    TechNet Community Support

  • How to fill an empty cell with the value above

    Hello,
    Please help me on the following issue related to BEx query and it's output in BEx analyzer as well as on Web.
    I am trying to modify a query output where the empty cells are to be filled with the value in the above cell.
    e.g. there is a column for transaction number, and this transaction number is the same for three rows, so it turns out to be two empty cells and only appears as if the transaction number applies to the first row only.
    not sure how to paste screenshot or attach document but would love to provide more information if the above isn't suffice.
    Please advise on what and where to modify in BEx designer.
    Thank you for your help!

    Thanks a lot...yes, now it works in BEx Analyzer but for some reason doesn't work in the Web view.
    Any ideas why is that?
    Thanks again for your prompt help.
    Edited by: One Idea on Jan 15, 2009 12:17 AM

  • Updating a DB table with only non-empty values of a work area

    Hi everybody,
    Is that possible in ABAP to update a table in the database with a work area, but only with non-empty values of this work area?
    Example:
    data: ls_custom type ZCUSTOMERS_0.
    ls_custom-CUSTOMER = '20'.
    ls_custom-LASTNAME = 'MyName'.
    ls_custom-FIRSTNAME = ' '.
    ls_custom-CURRENCY = ' '.
    update ZCUSTOMERS_0 from ls_custom.  *" I want that the update clause don't do the update with FIRSTNAME  and CURRENCY fields because they have empty values*
    If it's possible, how to do it?
    Thanks & regards,
    Abdel

    Total Questions:  81 (66 unresolved)
    Hi,
    To my understanding you mean if the database table has values
    customer         20
    lastname          somename
    firstname         firstname
    currency          INR
    so now after this
    data: ls_custom type ZCUSTOMERS_0.
    ls_custom-CUSTOMER = '20'.
    ls_custom-LASTNAME = 'MyName'.
    ls_custom-FIRSTNAME = ' '.
    ls_custom-CURRENCY = ' '.
    update ZCUSTOMERS_0 from ls_custom.
    you want the result as
    customer         20
    lastname          Myname
    firstname         firstname
    currency          INR
    Is it so? Then Normal update
    data: ls_custom type ZCUSTOMERS_0.
    ls_custom-CUSTOMER = '20'.
    ls_custom-LASTNAME = 'MyName'.
    update ZCUSTOMERS_0 from ls_custom.
    would do that.
    Thanks,
    Sri.

  • How to fill internal table with no data in debugging mode

    Hi all,
             I modified one existing program.Now I want to test it.I am not given test data.So in the middle of my debugging, I found that one internal table with no data.My problem is how to fill that internal table with few records in that debugging mode just as we change contents in debugging mode.If I want to proceed further means that internal table must have some records.
    Please I dont know how to create test data so I am trying to create values temporarily in debugging mode only.
    Thanks,
    Balaji

    Hi,
    In the debugging do the following..
    Click the Table button..
    Double click on the internal table name..
    Then in the bottom of the screen you will get the buttons like CHANGE, INSERT, APPEND, DELETE..
    Use the APPEND button to insert records to the internal table..
    Thanks,
    Naren

Maybe you are looking for

  • Code Analyzer

    I am currently using CF 4.5 on a Windows 2000 server and am trying to migrate to MX7 on Windows 2003. The code analyzer does not seem to want to analyze code on a remote server, so after I installed developer version and copied all the files over to

  • Ipod Touch doesn't charge while on, but charges while off?!

    Hi, I have an Ipod Touch 3rd Gen that I got shortly before xmas last year. The problem is that since the weekend it doesn't charge. I'm using a charger and my wife's ipod charges fine with it, so that rules out the charger. My problem is rather pecul

  • Executables not  found after copying oracle home

    Hi, I am cloning E-Business 11.5.10.2 on newly installed Red Had Linux 4.4. After copying oracle hoem frpm production server to test, i did not find executables in oracle_home/bin directory including sqlplus. I tried copying sqlplus from production s

  • Is Elements 7 compatible with windows 7 Home Premium 64 bit?

    I purchased a legal version of Photoshop Elements 7 from Adobe a couple years ago, and had it installed on a machine running (ugh) Vista 32 bit.  Now I have a completely new machine running 64 bit Win 7 Home Premium, with 8 GB RAM, quad core AMD etc

  • Service request lodged, doesn't process until server restarted.

    Hi, SCSM 2012 R2 RU3, being used as a front end portal for self service for orchestrator 2012 R2. I was wondering if anyone has come across an issue where a service request was lodged and the SR is in SCSM but without any status change to 'new' or an