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.
Author |
Topic |
shady4u
Starting Member
4 Posts |
Posted - 2012-07-09 : 23:07:21
|
I have two columns D_START_DATE AND D_END_DATE AS SHOWN BELOW2011-10-15 00:00:00.000 2011-11-14 00:00:00.0002011-11-14 00:00:00.000 2011-11-14 00:00:00.0002012-05-24 00:00:00.000 NULLAnd i want TO UPDATE D_END_DATE, SECOND ROW 2011-11-14 00:00:00.000 WITH 2012-05-24 00:00:00.000 FOR MORE THEN THOUSAND ID'S.QUERY SHOULD BE DYNAMIC OR IT SHOULD BE ABLE TO FETCH ID VS DATE AUTOMATICALLY. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-07-09 : 23:21:14
|
sorry your scenario is not clear. do you want to specifically look for only 2011-11-14 values or apply the logic throughout?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
shady4u
Starting Member
4 Posts |
Posted - 2012-07-09 : 23:27:53
|
Somehow we have screwed up SCD and we are planning to update in database one by one.what i have done is i am running this query to find out how many id's are repeatingSELECT columnname FROM tablename GROUP BY columnname HAVING COUNT(columnname) > 2.to begin with yes, i need to eliminate all strike 2011-11-14 00:00:00.000 where id=31572 and update with 2012-01-10 00:00:00.000.Only one row will be updated, because as per SCD second row will be expired and third row will be active.2011-10-15 00:00:00.000 2011-11-14 00:00:00.000 100342011-11-14 00:00:00.000 2011-11-14 00:00:00.000 315722012-01-10 00:00:00.000 NULL 83786 |
 |
|
shady4u
Starting Member
4 Posts |
Posted - 2012-07-11 : 05:25:49
|
any update on this please |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-07-11 : 10:07:16
|
quote: Originally posted by shady4u Somehow we have screwed up SCD and we are planning to update in database one by one.what i have done is i am running this query to find out how many id's are repeatingSELECT columnname FROM tablename GROUP BY columnname HAVING COUNT(columnname) > 2.to begin with yes, i need to eliminate all strike 2011-11-14 00:00:00.000 where id=31572 and update with 2012-01-10 00:00:00.000.Only one row will be updated, because as per SCD second row will be expired and third row will be active.2011-10-15 00:00:00.000 2011-11-14 00:00:00.000 100342011-11-14 00:00:00.000 2011-11-14 00:00:00.000 315722012-01-10 00:00:00.000 NULL 83786
isnt it enough to have generic update likeUPDATE tableSET D_END_DATE = '2012-01-10'WHERE D_START_DATE = D_END_DATE?first make it a select and see if it gives you only required rows before you make it an update------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|