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 |
Bazinga
Starting Member
19 Posts |
Posted - 2012-02-01 : 14:42:28
|
The database has a datatime field that stores combined birthdate. It also has three separate fields form year, month, day. There are several thousand records that have null values for the combined birthdate field, and I want to replace those null value with the YYYY,MM,DD from those three other fields.Would the following code work to update 250 records at a time, or is something else advisable.UPDATE TOP(250) corebio SET corebirthd = corebrthyr+corebrthmn+corebrthdywhere corebirthd IS NULL |
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2012-02-01 : 14:58:24
|
Iwould say rather not attempt to update every single record in a large table. Rather create a table with the exact same structure and insert all records in to the new table with the null fields now holding the correct values, then drop the original table and rename the duplicated table to the original table name. just ensure that you take care of all foreign key constraints etc ifthere are any present.Duane. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-01 : 15:08:15
|
if fields are integer you can use below logicUPDATE TOP(250) corebio SET corebirthd = DATEADD(day,corebrthdy-1,DATEADD(month,corebrthmn-1,DATEADD(year,corebrthyr-1900,0)))where corebirthd IS NULL i didnt understand need of TOP 250 though------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|