SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Syntax err converting datetime from character st
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Hommer
Aged Yak Warrior

784 Posts

Posted - 08/10/2007 :  12:03:02  Show Profile  Reply with Quote
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]

GO
Insert 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

United Kingdom
12543 Posts

Posted - 08/10/2007 :  12:25:45  Show Profile  Visit nr's Homepage  Reply with Quote
shuold work
try

insert tblA (txtSKU, colA, txtQty, DteTransDate) select '01', '10', '1', '19790222'

if that fails
CREATE 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.
Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

4612 Posts

Posted - 08/10/2007 :  12:28:51  Show Profile  Reply with Quote
You sample code works for me. You might want to take a look at SET DATEFORMAT in BOL.
Go to Top of Page

Hommer
Aged Yak Warrior

784 Posts

Posted - 08/10/2007 :  12:34:43  Show Profile  Reply with Quote
#tblA works but not regular tblA.
Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

4612 Posts

Posted - 08/10/2007 :  12:53:17  Show Profile  Reply with Quote
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)
Go to Top of Page

Hommer
Aged Yak Warrior

784 Posts

Posted - 08/10/2007 :  13:38:29  Show Profile  Reply with Quote
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')
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.07 seconds. Powered By: Snitz Forums 2000