Click here to Skip to main content
15,894,100 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have around 60 thousand records in my database and I need SQL statement can help me to update most of this records not the all because when we were entering the records we not know that one of the computer have different time we enter the records in the 9 am but the different computer was in 9 pm.

An example of the correct records are:

'2013-06-01 09:54:31.437'
'2013-05-31 09:55:33.857'
'2013-06-01 09:58:49.190'

and the wrong records are :

'2013-05-31 21:55:09.223'
'2013-05-31 21:56:41.337'
'2013-05-31 21:57:50.553'

Thank You For Helping Me
Posted

1 solution

Your question is not clear. Your list shows that some computers had the records at 9 pm, do you mean that the time portion is wrong and you want to fix it ?

I think this does it:

SQL
update blah set col = dateadd(hour, -12, col)
where datepart( hour, col) > 12



It says that in table blah, update the column called col to be 12 hours less than what it currently is ( so, from 9 pm to 9 am, from 10 pm to 10 am, from 10 am to 10 pm the previous day ), where the hour portion of the date is greater than 12 ( so the last example I gave would not occur, only times past midday, get 12 hours removed ). You can change the logic a little further if you need to, to suit your circumstance.
 
Share this answer
 
Comments
m.esmail 1-Jun-13 19:05pm    
Thank you so much for your support and quick response, I appreciate that.

The answer is very helpful.

Best regards
Christian Graus 1-Jun-13 19:15pm    
I am glad - honestly, it was the sort of thing I'd need to look up to do for myself, so I'm glad to hear it worked :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900