开发者

parser datetime via tsql

Update List set Date = "2009-07-21T19:00:40"

sql server doesn't recognize this format. is there a conversion fu开发者_JAVA百科nction


You can use CAST and CONVERT. But maybe you must replace the 'T' with a space, before you can convert it. (There are also string manipulation functions available.)


Worked just fine for me (SQL Express 2005) except for the double quotes (which SQL Server assumed was a column delimiter); is that what's throwing the error? Thanks for the sample code, but can you produce the actual error?

In other words,

DECLARE @List TABLE ( [date] DATETIME )

INSERT INTO @List SELECT GETUTCDATE()

UPDATE @List SET Date = "2009-07-21T19:00:40"

produces

Msg 207, Level 16, State 1, Line 7 Invalid column name '2009-07-21T19:00:40'.

Whereas

DECLARE @List TABLE ( [date] DATETIME )

INSERT INTO @List SELECT GETUTCDATE()

UPDATE @List SET Date = '2009-07-21T19:00:40'

runs successfully.


Try this:

UPDATE List SET Date = '2009/07/21 19:00:40'


Even worked for me too(2005 & 2008)..

DECLARE @tbl TABLE ( [date] DATETIME )
INSERT INTO @tbl SELECT getdate()
select * from @tbl

UPDATE @tbl SET Date = '2009-07-21T19:00:40'
select * from @tbl

However, just give a shot with DATEFORMAT COMMAND

Something like this

**SET DATEFORMAT dmy**

DECLARE @tbl TABLE ( [date] DATETIME )
INSERT INTO @tbl SELECT getdate()
select * from @tbl

UPDATE @tbl SET Date = '2009-07-21T19:00:40'
select * from @tbl
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜