Is there a way to update all columns in table from

2010-12-31 23:59:59.000

to

2010-12-31 00:00:00.000

Something like this??

UPDATE t1
SET [Posting Date] = [Posting Date] with ms = 00:00:00.000
WHERE ms = other than 00:00:00.000
GO
有帮助吗?

解决方案

UPDATE t1
SET [Posting Date] = cast([Posting Date] as date)
WHERE cast([Posting Date] as time) > '00:00'

其他提示

UPDATE t1
SET [Posting Date] = CAST([Posting Date] as DATE)

This may help you:

UPDATE tableName SET ColumnName = CAST( CAST( NOW( ) AS DATE ) AS DATETIME );

in sq-server

UPDATE [dbo].[1] SET  [datetime]= CAST([datetime] AS DATE) 

select * from [dbo].[1]

Try:

MODIFIEDDATETIME-(cast(MODIFIEDDATETIME as time))

This works for me:

update t1 set [Posting Date]  = CONVERT(varchar,[Posting Date] , 112)

But I suposse it deppends heavily on how are the locale of your database configured, you could need to use another style (instead 112, perhaps 101 or 102...) see this link to see the possible style for the conversion and choose the one that suits you better.

Alternative if you need to do this once, you could change the column type to date, save and then back to datetime, but if the table is big this could be time consuming

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top