Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Passing dates to Sql Server 2005 stored procedure

Hi,

I am trying to execute a SQL Stored procedure from Excel using VBA. Apart
from 2 string inputs, this proc also accepts two datetime imputs. When these
dates are passed via VBA, they are in the format "dd/mm/yyyy. However, the
SQL Server does not seem to accept dates passed in this format.
Applying different date formats in VBA does not help because eventually when
the dates shoot from Excel to SQL Server, they are in the format
"dd/mm/yyyy". I don't want to change the regional settings of the machine,
since it will only be a temporary solution.

This is the part of the code where I pass the date inputs to the procedu

Dim prm As ADODB.Parameter

Set prm = cmd1.CreateParameter("StartDate", adDate, adParamInput)
cmd1.Parameters.Append prm
cmd1.Parameters("StartDate") = sd

Set prm = cmd1.CreateParameter("EndDate", adDate, adParamInput)
cmd1.Parameters.Append prm
cmd1.Parameters("EndDate").Value = ed


Even though the code does not throw an error, the recordset does not return
anything. If I try passing dates like "2009-01-31" (yyyy-mm-dd), then the
recordset returns the expected output.

Is there any way, I can force Excel to pass dates in the format "yyyy-mm-dd"
without having to change the systems date time format settings?

Thanks,
Purnima
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Passing dates to Sql Server 2005 stored procedure


Excel stores dates as a number with Jan 1, 1900 being the number 1 and
Jan 2, 1900 being the number 2. Each hour is 1/24, and each minute is
1/(24*60).

So Jan 1, 1900 8:00 AM is 1 + 8/24 = 1.333333


You need to convert the excel date to a string using the FORMAT
function in VBA


StrDate = Format(MyDate,"yyyy-mm-dd")


Then use StrDate in you SQL statements.


--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?u=229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=207503

http://www.thecodecage.com/forumz

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Passing dates to Sql Server 2005 stored procedure

Thanks Joel.

But I am afraid this will not work for me.

We have a number of similar stored procedures all accepting date imputs and
changing the data type of the input is not an option for us. I cannot use
string in place of datetime in the stored procedure.

And because of this, using Format in Excel is not going to help.

I wish Excel would also let us change the International settings instead of
just read them. This would have solved my problem.

"joel" wrote:


Excel stores dates as a number with Jan 1, 1900 being the number 1 and
Jan 2, 1900 being the number 2. Each hour is 1/24, and each minute is
1/(24*60).

So Jan 1, 1900 8:00 AM is 1 + 8/24 = 1.333333


You need to convert the excel date to a string using the FORMAT
function in VBA


StrDate = Format(MyDate,"yyyy-mm-dd")


Then use StrDate in you SQL statements.


--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?u=229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=207503

http://www.thecodecage.com/forumz

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Passing dates to Sql Server 2005 stored procedure


You can still pass the date as a number and not a string. The only
place you need to convert to a string is on the SQL statement. Excel
will automatically convert a string date back to a number date.


--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?u=229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=207503

http://www.thecodecage.com/forumz

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Joining SQL Server Stored Procedure to SQL Server Table JimP Excel Programming 2 March 9th 09 09:14 PM
SQL Server Stored Procedure JimP Excel Programming 5 March 7th 09 12:22 PM
Problems execuiting a stored procedures in SQL Server 2005 wardellcastles Excel Programming 0 April 1st 08 10:48 PM
passing Nulls to SQL Server 2005 Smallweed Excel Programming 2 August 8th 07 03:10 PM
Passing an array or recordset to a stored procedure Robin Hammond[_2_] Excel Programming 1 December 2nd 04 05:15 AM


All times are GMT +1. The time now is 04:34 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"