Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Fill up missing value with value from previous date until next appearing date

$
0
0

Hello,

i have the following table:

CREATE TABLE [dbo].[fill_up](
	[date] [date] NULL,
	[value] [numeric](2, 1) NULL
) ON [PRIMARY]
GO
INSERT [dbo].[fill_up] ([date], [value]) VALUES (CAST(0x94360B00 AS Date), CAST(1.0 AS Numeric(2, 1)))
INSERT [dbo].[fill_up] ([date], [value]) VALUES (CAST(0x96360B00 AS Date), CAST(1.8 AS Numeric(2, 1)))
INSERT [dbo].[fill_up] ([date], [value]) VALUES (CAST(0x9A360B00 AS Date), CAST(2.5 AS Numeric(2, 1)))

I'm searching for a sql statement which fills up the missing dates. Afterwards it have to look like this: 

CREATE TABLE [dbo].[fill_up](
	[date] [date] NULL,
	[value] [numeric](2, 1) NULL
) ON [PRIMARY]
GO
INSERT [dbo].[fill_up] ([date], [value]) VALUES (CAST(0x94360B00 AS Date), CAST(1.0 AS Numeric(2, 1)))
INSERT [dbo].[fill_up] ([date], [value]) VALUES (CAST(0x96360B00 AS Date), CAST(1.8 AS Numeric(2, 1)))
INSERT [dbo].[fill_up] ([date], [value]) VALUES (CAST(0x9A360B00 AS Date), CAST(2.5 AS Numeric(2, 1)))
INSERT [dbo].[fill_up] ([date], [value]) VALUES (CAST(0x95360B00 AS Date), CAST(1.0 AS Numeric(2, 1)))
INSERT [dbo].[fill_up] ([date], [value]) VALUES (CAST(0x97360B00 AS Date), CAST(1.8 AS Numeric(2, 1)))
INSERT [dbo].[fill_up] ([date], [value]) VALUES (CAST(0x98360B00 AS Date), CAST(1.8 AS Numeric(2, 1)))
INSERT [dbo].[fill_up] ([date], [value]) VALUES (CAST(0x99360B00 AS Date), CAST(1.8 AS Numeric(2, 1)))

Do you have any suggestion how i can realize this?
Many thanks in advance. 

regards zerosonic


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>