Solved

SQL 7 datetime stored procedure parameter

Posted on 2000-04-26
4
683 Views
Last Modified: 2010-04-04

I'm having a problem passing a datetime parameter to an SQL 7 stored procedure.  I get an ODBC error - "Error converting datatype varchar to datetime".  The string is "01/01/2000 00:23:28.578"

I tried passing it as a string '2000.01.01 00:23:28.578' and using CAST ... AS DATETIME without luck too.  Tested the CAST and INSERT in Query Analyzer and they looked fine.

Delphi help, manual and D5 Developer's guide were no help.

-- Delphi 5 Code --

StoredProc1.Params[0].AsDateTime :=
      StrToDateTime(spDate+' '+sTime);
StoredProc1.Params[1].AsString :=
      sServer;
StoredProc1.Prepare;
StoredProc1.ExecProc;

-- SQL 7 Stored Procedure --

CREATE PROCEDURE [usp_InsertStat]
      @itime datetime,
      @server varchar(15)
AS
INSERT INTO stats (itime, server) VALUES (
      @itime,
      @server)

Can anyone help me out?

Thanks,

Scott
0
Comment
Question by:sfb
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
NetoMan earned 200 total points
ID: 2752849
Well, sounds like a problem with ODBC... but :

check StoredProc1.Params with the object inspector and set datetime to the param-type of param 0. (just in case is not).

Are you tried to pass only the date without time ?

(StoredProc1.Params[0].AsDate :=  StrToDate(spDate);

if works in this way, it will help to see where is the problem.

However, Why just don´t pass the param as string and then in the stored procedure you do the job of the conversion to datetime. As I see, you anyway do this conversion with the DateToStr function in Delphi.


NetoMan :)
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 2752901
I ran into the same problem a while back and ended up running the entire thing through DTS , making the conversion in VBScript during the transformation.  


Good luck!!
0
 

Author Comment

by:sfb
ID: 2753655

NetoMan -
I was planning to try your suggestion on my home computer (Win2000), unfortunately SQL Server is saying it is corrupted and I will need to reinstall.
I brought my work computer (notebook) home tonight, so I'll try soon.

DrDelphi -
I'm using a memorystream to rip through a large number of multi-megabyte, variable length records.  A fair bit of logic and manipulation needs to take place.  DTS may be able to handle it, but I don't think as quickly. ?

I have the program using dynamic SQL Insert statements, but I want to try stored procedures to compare speed.  Besides, I should know how.<g>

Scott
0
 

Author Comment

by:sfb
ID: 2753753

You forced me to take a closer look at how Params was indexed.  Looking at the Params in Object inspector I found that [0] in SQL 7 is a 'RETURN_VALUE'.

I switched to .ParamByName('@itime').AsDateTime and everything works well now.

Thanks,

Scott
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi XE2 application frozen on Windows 10 10 277
Mydac connection data base issue 3 140
delphi parse string to params 3 100
CheckListBox usage 3 51
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now