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 |
|
Prajwal
Starting Member
6 Posts |
Posted - 2005-06-29 : 19:51:59
|
| I have a date field in the table which has different values for all the different rows.I need a query to update the century from '19' to '20' in all the rows.The format is yyyy-mm-ddExample: The current date in the table is 1935-06-29...After I run the query,it should become 2035-06-29...Can someone please help!!!Thanks!!! |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-06-29 : 19:55:16
|
| Make sure this is correct before running the UPDATE:SELECT DATEADD(yy, 100, YourColumn) AS YourColumnFROM YourTableThe update:UPDATE YourTableSET YourColumn = DATEADD(yy, 100, YourColumn)Tara |
 |
|
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2005-06-29 : 20:10:47
|
| WHERE Year(YourColumn) < 2000HTH================================================================='Tis with our judgements as our watches: none Go just alike, yet each believes his own. -Alexander Pope, poet (1688-1744) |
 |
|
|
Prajwal
Starting Member
6 Posts |
Posted - 2005-06-29 : 22:52:01
|
| Thanks for your replies...Thanks tduggan... but Dateadd wasn't recognized...Thanks Bustaz Kool...But,The values are different in each row...So, I can't update the same value...Wherever there is 19, it needs to change to 20Exaple:1935 needs to change to 20351946 needs to change to 2046........................................................etc...any more help ...please...Thanks!!! |
 |
|
|
nosepicker
Constraint Violating Yak Guru
366 Posts |
Posted - 2005-06-29 : 23:40:16
|
| Is your date field char or varchar? If so, then:UPDATE YourTable SET YourDateColumn = STUFF(YourDateColumn, 1, 2, '20') WHERE LEFT(YourDateColumn, 2) = '19' |
 |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2005-06-30 : 07:20:31
|
| what do you mean dateadd was not recognized?is this mssql or access?--------------------keeping it simple... |
 |
|
|
Prajwal
Starting Member
6 Posts |
Posted - 2005-06-30 : 15:58:25
|
| DATEADD worked...Thanks for your help 'tduggan' and other guys!!! |
 |
|
|
|
|
|
|
|