views:

35

answers:

2

Hi I am trying to insert the following to SQL Server 2005:

INSERT INTO tb_UserLoginTimes (UserID, LoginDateTime)
VALUES (1235,2010/07/06 10:38:44)

But am getting the following error.

Incorrect syntax near '10'.

Do I need to escape the colon?

If so how do I do that?

Real noob at this so my apologies.

+5  A: 

It looks like you simply need to enclose your date in quotes:

... VALUES (1235, '2010/07/06 10:38:44')

Try it out in the SEDE. If you leave out the quotes, you'll get the same syntax error you're reporting.

Daniel Vassallo
Bingo - apparently I have to wait to accept the answer. - Anyway thanks.
Chin
+2  A: 

Instead of 2010/07/06 10:38:44 use the ANSI SQL Standard (YYYYMMDD HH:MM:SS)

'20100706 10:38:44'
ANSI? Although the one you've used is one of only two SQL Server 2005 DATETIME representations that is considered unambiguous as regards language settings, it is other *other* one that most closely resembles the ANSI Standard i.e. `'2010-07-06T10:38:44'`. The actual ANSI Standard omits the `T`.
onedaywhen