Author |
Topic |
Hommer
Aged Yak Warrior
808 Posts |
Posted - 2007-08-10 : 12:03:02
|
Hi,I have next table, but all my 3 INSERTs failed. Syntax error converting datetime from character string.What is the trick here? Server setting? Locale? Thanks!if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tblA]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)CREATE TABLE [tblA] ( [txtSKU] [varchar] (20), [colA] [varchar] (50) , [txtQty] [varchar](10) NULL , [DteTransDate] datetime NULL) ON [PRIMARY]GOInsert INTO tblA Values('01', '10', '1', '19790222')Insert INTO tblA Values ('01', '10', '1', CONVERT(DateTime, '01/30/99', 1))Insert INTO tblA Values ('02', '1', '2', '11/30/2005')select CONVERT(DateTime, '01/30/99', 1) |
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2007-08-10 : 12:25:45
|
shuold worktryinsert tblA (txtSKU, colA, txtQty, DteTransDate) select '01', '10', '1', '19790222'if that failsCREATE TABLE #tblA ([txtSKU] [varchar] (20),[colA] [varchar] (50) ,[txtQty] [varchar](10) NULL ,[DteTransDate] datetime NULL)insert #tblA (txtSKU, colA, txtQty, DteTransDate) select '01', '10', '1', '19790222'==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2007-08-10 : 12:28:51
|
You sample code works for me. You might want to take a look at SET DATEFORMAT in BOL. |
|
|
Hommer
Aged Yak Warrior
808 Posts |
Posted - 2007-08-10 : 12:34:43
|
#tblA works but not regular tblA. |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2007-08-10 : 12:53:17
|
I've never had that sort of issue, but it's leading me to think that you have a difference in settings between TempDB and the db you are working in. There are others here that no more about the DB settings than I, but I'd look and see if you can detect a config difference.As to why you cannot insert a Date, that is strange..Can you do simple selects and get the proper results?I.E: SELECT CAST('20010101' AS DATETIME)SELECT CONVERT(DateTime, '01/30/99', 1) |
|
|
Hommer
Aged Yak Warrior
808 Posts |
Posted - 2007-08-10 : 13:38:29
|
Yes, I did SELECT CONVERT(DateTime, '01/30/99', 1), and I got the right 1999-01-30 00:00:00.000.Also, this did not solved the problem.SET DATEFORMAT mdy;Insert INTO tblA Values ('02', '1', '2', '11/30/2005') |
|
|
|
|
|