Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Duplicate data n times

$
0
0
Dear NGI have a table "Beginn" with a datefield (Datum), a Price field (Wert) and a counter field (CNT). The problem which I have is I need to create a loop which sets new values to datum, Wert while the CNT field is bigger then 1following steps should be taken:1. Price / Wert only the first time this value should be the new Wert2. Add every new recordset a new month to the date field3. decrease the countfield -1So the Beginn table is what I have and the Ziel table is what I need. Can anybody tell me how to create a loop in SQL? In VBA it would be a Do while CNT > 0 Many thanks for your helpBest regards Chris[code="SQL"]create table dbo.Beginn(Bold_ID int,Wert int,Datum datetime,CNT int);create table dbo.Ziel(Bold_ID int,Wert int,Datum datetime);Insert Into BeginnValues(1,300,'2016-01-01 00:00:00',3),(2,100,'2016-01-01 00:00:00',2);Insert Into ZielValues(1,100,'2016-01-01 00:00:00'),(1,100,'2016-02-01 00:00:00'),(1,100,'2016-03-01 00:00:00'),(2,50,'2016-01-01 00:00:00'),(2,50,'2016-02-01 00:00:00');[/code]

Viewing all articles
Browse latest Browse all 3145

Trending Articles