I have a table with a column in it called Date, which is of the type DateTime, and for the last two years I have been adding data which I found out was incorrect.
My dates are all a day in the future, so I need to reduce each date by one day.
I can easily use a select script to reveal the 25,000 rows which are all incorrect dates. But I can't figure out how to update each and every row to subtract one day from each date.
So where I have:
26/01/2005
I would like to have:
25/01/2005
and of course for every record. Obviously way too many to do manually :-(
Can anyone show me a script that will get what I'm after.
Tia
Tailwag
After one your 25000 rows with invalid data, that is not nice to find out. But it is easy to solve, just run this query:
UPDATE [MyTable] SET [MyDate] = DATEADD(year, -1, [MyDate])
Don't forget to replace MyTable with your table name and MyDate with your datetime field name.
I have tested it before posting this solution, because i don't want to be responsible for lozing 25000 rows on friday.|||
Also, replace year with day!
So the update query must be:
UPDATE [MyTable] SET [MyDate] = DATEADD(day, -1, [MyDate])
- Jeroen Boiten
|||Indeed! Thanks Jeroen, i overlooked that one. Thought only the years where incorrect.|||
Thank you PJ, and also Jeroen. I ran the query and 'Viola' it worked flawlessly, you guys are now extremely high on my best friends of all time list
Tia.
Tailwag
P.S. The B_ _ _ _ Friday curse has finally been thwarted!!!
No comments:
Post a Comment