Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
I have a table with the fields:id ,startDate, endDate, actionwhen the endDate>= 31/12/1999I want to set the end date to 31/12/1999and add a new row:id,1/1/2000, endDate(original),actionI still cover the time period I had before - but using 2 records and not just one. the reason for all this is that records after 1/1/2000 should be calculated according to new rules.The Question:It's very easy to make this happen with a cursor but it takes forever... is there a way to do the same job with a query?ThanksAsaf
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2009-07-12 : 08:25:43
seems like this
INSERT INTO YourTableSELECT id ,'1/1/2000', endDate, actionFROM YourTableWHERE endDate>= '31/12/1999'UPDATE tSET t.endDate='31/12/1999'FROM YourTable tWHERE endDate>= '31/12/1999'AND StartDate <> '1/1/2000'