Home Forums SQL Server 2008 T-SQL (SS2K8) column value balancing (copy previous value <> NULL) RE: column value balancing (copy previous value <> NULL)

  • Hi John,

    Here's the new testtable with data (works also on SQL Server 2005)

    as you can see there are 3 different category,class location combinations in this testfile

    category=111

    class=5010

    location=210

    category=111

    class=5010

    location=230

    category=111

    class=5010

    location=240

    for every category,class,location combination RowNum starts with 1 (row 1 has always values)

    success

    Regards,

    Dick Herberts

    CREATE TABLE [dbo].[TestTable](

    [RowNo] [int] NULL,

    [Category] [char](3) NULL,

    [Class] [char](4) NULL,

    [Location] [char](3) NULL,

    [Datum] [datetime] NULL,

    [Owned] [int] NULL,

    [Beschikbaar] [int] NULL,

    [OnRent] [int] NULL

    ) ON [PRIMARY]

    INSERT INTO TestTable

    VALUES

    (1,'111','5010','210','20100101', 12,1,0),

    (2,'111','5010','210','20100102', NULL,NULL,NULL),

    (3,'111','5010','210','20100103', 13,8,NULL),

    (4,'111','5010','210','20100104', 12,NULL,3),

    (5,'111','5010','210','20100105', 12,5,NULL),

    (6,'111','5010','210','20100106', 15,6,4),

    (7,'111','5010','210','20100107', NULL,NULL,3),

    (8,'111','5010','210','20100108', NULL,17,0),

    (9,'111','5010','210','20100109', 7,16,1),

    (10,'111','5010','210','20100110', NULL,18,NULL),

    (11,'111','5010','210','20100111', 12,1,2),

    (12,'111','5010','210','20100112', NULL,6,6),

    (13,'111','5010','210','20100113', NULL,NULL,NULL),

    (14,'111','5010','210','20100114', NULL,NULL,NULL),

    (1,'111','5010','230','20100101', 1,17,2),

    (2,'111','5010','230','20100102', NULL,1,NULL),

    (3,'111','5010','230','20100103', 13,NULL,1),

    (1,'111','5010','240','20100101', 2,0,2),

    (2,'111','5010','240','20100102', NULL,3,NULL),

    (3,'111','5010','240','20100103', 12,5,10),

    (4,'111','5010','240','20100104', 1,NULL,NULL),

    (5,'111','5010','240','20100105', NULL,6,5),

    (6,'111','5010','240','20100106', 7,NULL,35),

    (7,'111','5010','240','20100107', NULL,NULL,36),

    (8,'111','5010','240','20100108', NULL,1,NULL),

    (9,'111','5010','240','20100109', 4,3,7),

    (10,'111','5010','240','20100110', NULL,8,NULL),

    (11,'111','5010','240','20100111', NULL,NULL,NULL);