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

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

  • 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

  • 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.

  • Need to extract non empty value thru MDX

    Hi All,
    I have a requirement where there are 2 measures A and B.. I need to populate the first non-missing value from a layer from A in to B..
    tried using HEAD function however looks like in ASO MDX member formulas does not support this ..
    Any help would be highly appreciated
    Thnks,

    I believe the issue is that the formula you are using returns a set and you are looking for a value. Therefore, you need to use the Head function with a function that returns a numeric value (ie: Sum, Max, Avg, etc). In instances like this I typically use the Sum function. Depending on your cube and the rest of your formula, you may need to put some additional work into the formula so that the Sum returns just the value you need, but it just requires getting more specific in your arugments.
    The Head formula will bring back the first member or tuples specified, but won't evaluate for non-missing. You may need to also combine the Head forumla with the Filter formula. ex: Sum(Head(Filter([Dimension or Member].SetFunction,[A] <> Missing)),1) You will mostly need to select some other dimension to apply the filter to (like period or scenario). Examples of the SetFunction are Children, Members, Levels(0), etc. If you end up going this route you may want to write out your Sum(Head()) function and and Sum(Filter()) function and validate each independently and then merge. I find this helps when trying to build larger nested functions.
    Hope this helps!
    Jen

  • Implementing the Last Non Empty

    Dear All,
    I am trying to get the last non empty set by applying the Last Non Empty property to the measures Projectedvalue and Gross amount.  The below is the original table.
    The output I want is as below:
    For the Revised Quarter type Original all the recent values of the Projected quarter should be displayed.
    As you can see the last value for Q1 needs to be selected which is shown in above pic.
    Currently the cube output is same as the original table. :(
    Can anybody help me on this?
    Thanks, Franco.

    Hi Franco,
    In SQL Server Analysis Services (SSAS), LastNonEmpty is an aggregation function available in the Enterprise version of SQL Server. Essentially, you simply create a calculated member that returns the non empty value, or if empty, it looks in the previous
    member. Please take a look at the articles regarding Last Ever Non Empty.
    Getting the last non empty value
    The Last Non Empty Dilemma
    Last Ever Non Empty – a new, fast MDX approach
    Regards,
    Charlie Liao
    TechNet Community Support

  • Mdx : Sum up the measure from start but need only non empty rows

    Hi All
    i have created a calculated measure where it suming up all its previous avaialable values based on Date dimension.
    Everything is working but we are getting all rows from that datetimension . how can get only till current date,
    SUM(NULL:[Date].[Hierarchy].currentmember,[Measures].[SIMID])
    Surendra Thota

    Hi Surendra,
    According to your description, you want to calculate the sum up the measure from start for those non empty rows, right?
    In this case, please try the query below.
    WITH MEMBER [Measures].[Sum from start]
    AS
    SUM ({NULL:[Date].[Calendar].CurrentMember},
    [Measures].[Internet Sales Amount])
    SELECT {[Measures].[Internet Sales Amount],[Measures].[Sum from start]} ON 0 ,
    nonempty([Date].[Calendar].[Calendar Year].MEMBERS) ON 1
    FROM [Adventure Works]
    Result
    Besides, here is a blog which describe various way to calculate running total, please see:
    http://blog.sqltechie.com/2011/01/various-way-to-calculate-running-total.html
    Regards,
    Charlie Liao
    If you have any feedback on our support, please click
    here.
    Charlie Liao
    TechNet Community Support

  • Delete non-empty directory: better solution than traversal?

    So far, I'm only able to delete a directory via File.delete() when I delete each single file in this directory and recursively in any subdirectories. I wonder if there is a better/easier way to delete non-empty directories?

    Yes, it takes a fraction of a second. To be exact: about 0.3 seconds in our cases for each temporary directory with about 1.5 MB content and less than 100 files.
    But during big reports with hundreds of pages, each pages producing several such temp directories, this deletion takes about 5-10 seconds for a full report. Now, we have several customers with several users generating reports all over the place and reducing processing time is of good value. 10 seconds less for reports the user is waiting for might not be a big deal for you but for our customers.
    I read in some Linux forums that some file systems just remove the root directory out of some tree structure without recursing the whole tree. That's why deletion is so fast and "real deletion" (to not be able to undelete files) is slow. Unfortunately, we have Windows servers ...

  • Compare previous with Current Value

    Want to compare previous with current value and assign the right one..
    COLA COLB
    72 21356
    41023 21356
    90 78903
    90 89078
    90 78956
    90 45632
    41023 78903
    41023 45632
    Output I want is:
    COLA COLB
    72 21356
    72 21356
    90 78903
    90 89078
    90 78956
    90 45632
    90 78903
    90 45632
    Anytime the value in COLA is 41023, I need to look at value in COLB and compare it with the rest of values and assign the COLA value that is NOT 41023
    Thanks...

    Not sure but here a try :
    SQL> select * from tbltbl;
          COLA       COLB
            72      21356
         41023      21356
            90      78903
            90      89078
            90      78956
            90      45632
         41023      78903
         41023      45632
    8 rows selected.
    SQL> MERGE INTO tbltbl a
      2  USING (select c.cola,b.rowid rwd
      3         from   tbltbl b,
      4                tbltbl c
      5         where  b.cola=41023
      6         and    b.colb=c.colb
      7         and    c.cola!=41023) d
      8  on    (a.rowid=d.rwd)
      9  WHEN MATCHED THEN UPDATE set a.cola=d.cola;
    3 rows merged.
    SQL>
    SQL> select * from tbltbl;
          COLA       COLB
            72      21356
            72      21356
            90      78903
            90      89078
            90      78956
            90      45632
            90      78903
            90      45632
    8 rows selected.Works only if colb is unique for non 41023 value.
    Nicolas.
    Oh, very very late.
    Edited by: N. Gasparotto on Oct 3, 2008 5:05 PM

  • Can't change cell's type on a non-empty cell!

    Can't change cell's type on a non-empty cell!
    I need to empty cell, then change the type, then retype the value of a cell.
    Number 3 on Maverics.
    File was created on Numbers 2.3
    Thank you.

    Alazarev,
    Can you post a screenshot showing the problem.  You can select the cell(s) then adjus the formatting as needed using the Cell format tool on the right.

  • Silent Install -- ignore Non Empty Home

    Doing a 10g install in Silent mode and wondering how I can get past the Non Empty home message.
    During the interactive install, you simply say ignore or continue. I cleared all of the files in the $ORACLE_HOME prior to the install, but it creates a log file in that directory as that is also the $UNIX_HOME. I cannot change the ORACLE_HOME destination because of backup scripts and cannot do an interactive install. So, does anyone know how to bypass the OUI-10029 message during a silent install using a responsefile?
    Thanks.

    Prakash,
        Thank you for the reply.  This error occurs in a previously empty directory.  The oracle installer adds a log and lock directory.  I am using the -force flag only to get around the installer files (not to be confused with the /tmp installer files elsewhere).  I thought about turning validation off but I still need it.
    I can't access the bug.  Is there a way to force the installer to not write to the empty directory before it validates that is is empty by writing the log and lock directory elsewhere?
         However, with the -novalidation flag the WebLogic 12.1.2.0 silent install is proceeding - I will verify it shortly
    Check complete. The overall result of this check is: Passed
    CertifiedVersions Check: Success.
    Expected result: 1.7
    Actual Result: 1.7.0_51
    Check complete. The overall result of this check is: Passed
    CheckJDKVersion Check: Success.
    Verifying data......
    Copying Files...
    -----------20%----------40%----------60%--
    thank you
    Michael

  • Null and Empty Values

    Hi All,
    Is there a parameter which allows me to translate automatically the instruction
    select * from table_a where col_a = ''
    in
    select * from table_a where col_a is null
    Thanks

    Not in Oracle, no. col_a = NULL and col_a IS NULL are logically distinct clauses. If you are dealing with NULL's, you absolutely must use three-valued logic in your statements.
    Depending on what you are doing, you may be able to throw an NVL on col_a to ensure a non-NULL value is returned.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • System.Exception: null or empty values

    Have designed a 4 part form Using DW MX, ASP.NET C# and MySQL
    and currently getting the below error when moving from one page to
    the next.
    The web.config file is on the server, there are no null or
    empty values, and the key tags match.
    I am new to applicaiton development in DW and am now stuck -
    any suggestions?
    System.Exception: This page has a MM:DataSet, MM:Insert,
    MM:Update or MM:Delete tag with a null or empty value for the
    ConnectionString and DatabaseType attributes.
    Often, such values come from application settings in the
    web.config file. That file might be missing from the server
    executing this page. Or, it might be missing the particular add key
    tags for the database connection this page uses. If you are using
    Dreamweaver, look for the web.config file in the local root folder
    of your Dreamweaver site. Once you find this file, you can either:
    Put this file onto the server that is executing this page.
    Copy the add key tags from the web.config in the local root
    folder of your Dreamweaver site and paste them into the web.config
    file in the server that is executing this page.
    at DreamweaverCtrls.DataSet.DoInit()
    Text

    http://java.sun.com/docs/books/tutorial/uiswing/components/spinner.html#model
    Might be a good start.

  • Passing null/empty values from a actionscript VO to a Coldfusion ORM object

    This is the situation.
    If you have an actionscript VO that binds to a Coldfusion ORM object via the RemoteClass metadata and some of the values are not set, null, or empty strings and you pass it from Flex to Coldfusion then the Coldfusion deserialization barfs saying the values are not acceptable date values (for type="date") or valid emails (for validation="email") or other such validations, even if required="false" on the property.
    For instance, if you have the following actionscript VO:
    package vo
        [RemoteClass(alias="com.companyname.Person")]
        [Bindable]
        public class Person
            public var person_id:Number;
            public var last_name:String;
            public var first_name:String;
            public var email:String;
            public var created_date:date;
         public function Person() {}
    And you have the corresponding Coldfusion component:
    <cfcomponent displayname="person" output="false"
        alias="com.companyname.Person"
        schema="dbo" persistent="true"
        table="PERSON">
        <cfproperty name="person_id" type="numeric" fieldtype="id" validate="integer" required="true" column="PERSON_ID"/>
        <cfproperty name="last_name" type="string" column="LAST_NAME" required="true"/>
        <cfproperty name="first_name" type="string" required="true" column="FIRST_NAME"/>
        <cfproperty name="email" type="string" validate="email" required="false" column="EMAIL"/>
        <cfproperty name="date_created" type="date" required="false" column="DATE_CREATED"/>
    </cfcomponent>
    Then if you pass the actionscript VO as is to Coldfusion, the deserialization complains that you do not have a valid email or a valid date for date_created.  This is bad, bad, bad.  Essentially if you have a validation of certain types (email being one) or a date property, or probably some other cases, then you essentially can not make it not required, it automatically makes it required because the Coldfusion serializer considers null/empty values as invalid dates or emails.  But the serializer should not care for values that are not required, there has to be a way to pass null/empty values to these data types, but apparently there's not.  If you pass an empty string ("") you still have the same problem.  I know Coldfusion does not have null values, but there has to be a way to do this, otherwise it defeats the purpose of having required="false" and some kind of validation on the property.
    There seems to be two ways around it.  One is to override the implicit setters for the properties on the Coldfusion side and check for 0 length values yourself, then set the property if it is not, or create your own validation routine.  I ended up creating my own validation function since I didn't want to have to write a setter function for everyone of these cases and I can pass back user friendly validation messages.
    Have other people encountered this problem?  How have you gotten around it?  Thanks.

    I realize that I didn't clarify that I am using ColdFusion
    for getting the data. This class was generated by the Create CFC
    wizard in Flex Builder.
    package com.generated
    [Managed]
    [RemoteClass(alias="components.generated.clients.Clients")]
    public class Clients
    public var clientid:Number = 0;
    public var clientfirstname:String = "";
    public var clientlastname:String = "";
    public var clientaddress1:String = "";
    public var clientaddress2:String = "";
    public var clientcity:String = "";
    public var clientstate:String = "";
    public var clientzip:String = "";
    public var clientphone:String = "";
    public var clientemail:String = "";
    public function Clients()
    }

  • Passing null/empty values from Flex to a Coldfusion ORM object

    This is the situation.
    If you have an actionscript VO that binds to a Coldfusion ORM object via the RemoteClass metadata and some of the values are not set, null, or empty strings and you pass it from Flex to Coldfusion then the Coldfusion deserialization barfs saying the values are not acceptable date values (for type="date") or valid emails (for validation="email") or other such validations, even if required="false" on the property.
    For instance, if you have the following actionscript VO:
    package vo
        [RemoteClass(alias="com.companyname.Person")]
        [Bindable]
        public class Person
            public var person_id:Number;
            public var last_name:String;
            public var first_name:String;
            public var email:String;
            public var created_date:date;
         public function Person() {}
    And you have the corresponding Coldfusion component:
    <cfcomponent displayname="person" output="false"
        alias="com.companyname.Person"
        schema="dbo" persistent="true"
        table="PERSON">
        <cfproperty name="person_id" type="numeric" fieldtype="id" validate="integer" required="true" column="PERSON_ID"/>
        <cfproperty name="last_name" type="string" column="LAST_NAME" required="true"/>
        <cfproperty name="first_name" type="string" required="true" column="FIRST_NAME"/>
        <cfproperty name="email" type="string" validate="email" required="false" column="EMAIL"/>
        <cfproperty name="date_created" type="date" required="false" column="DATE_CREATED"/>
    </cfcomponent>
    Then if you pass the actionscript VO as is to Coldfusion, the deserialization complains that you do not have a valid email or a valid date for date_created.  This is bad, bad, bad.  Essentially if you have a validation of certain types (email being one) or a date property, or probably some other cases, then you essentially can not make it not required, it automatically makes it required because the Coldfusion serializer considers null/empty values as invalid dates or emails.  But the serializer should not care for values that are not required, there has to be a way to pass null/empty values to these data types, but apparently there's not.  If you pass an empty string ("") you still have the same problem.  I know Coldfusion does not have null values, but there has to be a way to do this, otherwise it defeats the purpose of having required="false" and some kind of validation on the property.
    There seems to be two ways around it.  One is to override the implicit setters for the properties on the Coldfusion side and check for 0 length values yourself, then set the property if it is not, or create your own validation routine.  I ended up creating my own validation function since I didn't want to have to write a setter function for everyone of these cases and I can pass back user friendly validation messages.
    Have other people encountered this problem?  How have you gotten around it?  Thanks.

    Looks like a known workaround to this issue is to wrap the Flex object in an array.
    The ColdFusion CFC will accept that as an array, with the first an only element being a struct, which is the object you built in Flex.

Maybe you are looking for

  • Call EJB From Oracle Stored proc or Database loaded Java?

    Are there any examples of calling an EJB, residing in the OC4J on a machine separate from the DB server, from an Oracle PL/SQL stored proc. The Stored proc can call java loaded into the DB. That java makes the intial bean context. Or another way if s

  • Sending an Internal Table as an excel  via email

    Hi, The data is coming properly in excel. But, the thing is first row is coming an empty one.and in second row headings are started and from third row data is coming. what i want is first row should come with headings and from second row data should

  • ITunes hangs when i edit preferences or have to enter a password

    Hi all, I have a weird problem at the moment where if I edit preferences or iTunes asks for a password when I enter the iTunes store the whole app hangs. The only way O can get out of it is to go into Task Manager and End Task. anyone experienced thi

  • Parts of screen missing when played on Internet Explorer

    Has anyone ever had a published CP5 project not display the whole screen when presented in Internet Explorer?  A coworker brings up a course in IE and the playbar and the right side of the screen are missing.  I bring up the same course from the same

  • Save / export screen grab with in DVD pro

    Hello I noticed that somewhere within DVD pro you have the option to save/export the a frame from a track as an image file, tiff etc. And now I can't find it, could somebody point me in the right direction? thanks