Inserting a date into SqlServer 2012

General discussion forum about all databases other than SqlBase.
monchotgu
Honduras
Posts: 76
Joined: 24 Apr 2017, 02:55
Location: Honduras

Inserting a date into SqlServer 2012

Post by monchotgu » 01 Feb 2016, 02:52

I have always worked wth Sqlbase, but I have a project in SqlServer (Of which I know very little), but when I try to do an insert/ update with a datetime field I get the following error:

[Microsoft][SQL Server Native Client 11.0]Invalid character value for cast specification...

I have the following Insert Statement:
INSERT INTO dbo.colaboradores (Anio,Pais,ID_Usuario,Apellido,Nombre,Level,fecha_Ingreso ) Values (:nAno,:sPais,:sDatos[0],:sDatos[1],:sDatos[2],:sDatos[3],:dtFecIng)

the value of dtFecIng (as Seen in the debugger) is: 2003-03-07-01.01.01.000000

Can anybody guide me on what I am doing wrong?

Thanks in advance

FRBhote
India
Posts: 2177
Joined: 09 Mar 2017, 05:32
Location: Hyderabad, India

Re: Inserting a date into SqlServer 2012

Post by FRBhote » 01 Feb 2016, 06:25

You should not get that error, but sqlbase has a DATE data type which sqlserver does not. When comparisons take place, the time can cause all sorts of problems and you will not get the equality. Advisable to make the time part always zero.


Set dtCurrent = SalDateConstruct( SalDateYear( dtCurrent ), SalDateMonth( dtCurrent ), SalDateDay( dtCurrent ), 0, 0, 0 )

MSchmidt
Germany
Posts: 299
Joined: 03 Jul 2017, 09:28
Location: Germany

Re: Inserting a date into SqlServer 2012

Post by MSchmidt » 01 Feb 2016, 10:13

Try to change the ODBC Driver from SQL Server Native Client 11.0 to SQL Server

We always use this one since many years with different kind of TD versions

And I remember error messages, if we used one of the native clients.


regards

M.Schmidt

a_sivababu
India
Posts: 501
Joined: 10 Mar 2017, 08:46
Location: Chennai,India

Re: Inserting a date into SqlServer 2012

Post by a_sivababu » 01 Feb 2016, 12:20

After changing to SQL Server driver, set the dateformat through SET DATEFORMAT if you still face problem.

Regards
Siva A

monchotgu
Honduras
Posts: 76
Joined: 24 Apr 2017, 02:55
Location: Honduras

Re: Inserting a date into SqlServer 2012

Post by monchotgu » 01 Feb 2016, 18:16

Thanks to all I will give it a try.!!

Return to “General Discussion”

Who is online

Users browsing this forum: [Ccbot] and 0 guests