Re: Passing Dates to stored procedure - parameter headache.
- From: blueboy1894 <blueboy1894@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 4 Jan 2007 04:03:01 -0800
Hi Alex
Thanks once again. I eventually also worked out that I had to change the
command type because I'm now running a command, not a stored procedure. This
works a treat though and is much easier than adding the parameters manually.
This has moved me on a big step so thanks again.
"Alex Dybenko" wrote:
Hi,.
try to add exec:
"exec spGetOrdhed '4332', '20070102'"
--
Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com
"blueboy1894" <blueboy1894@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:6AF21EE3-EE42-498B-B73A-C0FE5176A6C6@xxxxxxxxxxxxxxxx
Hi Alex. many thanks for your response.
This nearly works, updating the command text to read { call spGetOrdhed
'4332', '20070102' }
but then I get a Syntax error or Access Violation (80040e14 ) when I try
and
execute the command, and not entirely sure why - the same values work fine
in
the SQL Query Window.
Any idea why?
"Alex Dybenko" wrote:
Hi,
try to use adDate instead of adDBTimeStamp
then you can also pass parameters in command string as text:
"spGetOrdhed " & "'" & Me!custcode & "','" &
format(Me!deldate,"yyyymmdd") &
"'"
so both customer and date in single quotes
--
Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com
"blueboy1894" <blueboy1894@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:E918EB0E-0352-48DF-B409-2F9DB842B40E@xxxxxxxxxxxxxxxx
Hi all
I am trying to pass a date as an input parameter from VBA to a stored
procedure in SQL 2005. The stored procedure looks like this:
ALTER PROCEDURE [dbo].[spGetOrdhed]
@customer varchar(5),
@deliverydate datetime
AS
BEGIN
SET NOCOUNT ON;
SELECT ordhed.ordhedid, ordhed.deldate, custac.[name], ulpfil.descr
FROM freshsql1.Company1.dbo.custac INNER JOIN
freshsql1.Company1.dbo.ordhed ON custac.custcode = ordhed.custcode
INNER
JOIN
freshsql1.Company1.dbo.ulpfil ON ordhed.dp = ulpfil.dp
WHERE (ordhed.custcode = @customer) AND (ordhed.deldate =
@deliverydate)
END
And the VBA passing the parameter values looks like this:
Dim cmd1 As ADODB.Command
Dim prm1 As ADODB.Parameter
Dim prm2 As ADODB.Parameter
Dim rst1 As New ADODB.Recordset
Dim cust1 As String
Dim date1 As Date
Dim myDate As Date
Dim str1 As String
cust1 = Me!custcode
date1 = Me!deldate
myDate = Format(CDate(date1), "yy/mm/dd")
Set cmd1 = New ADODB.Command
cmd1.ActiveConnection = "DSN=complaints2005;"
cmd1.CommandType = adCmdStoredProc
cmd1.CommandText = "[dbo].[spGetOrdhed]"
Set prm1 = cmd1.CreateParameter("@customer", adVarChar, adParamInput,
5)
prm1.Value = cust1
cmd1.Parameters.Append prm1
Set prm2 = cmd1.CreateParameter("@deliverydate", adDBTimeStamp,
adParamInput)
prm2.Value = myDate
cmd1.Parameters.Append prm2
Set rst1 = New ADODB.Recordset
Set rst1 = cmd1.Execute
(then do some looping to display the results).
I have a problem with the value which is being passed to the variable
myDate. Basically, I cannot get it to form a date value which is valid
on
the
SQL server. The form control accepts values in dd/mm/yyyy format.
The deldate field in SQL is a datetime type and looks like this:
YYYY-MM-DD HH:MM:SS.mmm (milliseconds at the end), though the time part
of
this in the data is always represented as all zeros.
Running the procedure in SQL is fine, and accepts values OK. The
problem
is
on inspection in the immediate window my code generates the value for
myDate
of 07/01/2002, instead of the 07/01/02 which I am trying to pass. I
have
tried all the date functions I can think of to get this to pass
correctly -
Format, CDate, Date Serial etc, and even tried writing it into a
CONVERT
statement as part of the stored procedure. The result is, of course
that
the
recordset winds up empty because there are no entires for that customer
on
that date.
Can anyone enlighten me as to where I am going wrong with this? I'd be
very
grateful as if I can get this to work then the rest of my task should
be
relatively simple (select a specific record and pull the detail on an
order
number).
Thanks,
- References:
- Passing Dates to stored procedure - parameter headache.
- From: blueboy1894
- Re: Passing Dates to stored procedure - parameter headache.
- From: Alex Dybenko
- Re: Passing Dates to stored procedure - parameter headache.
- From: blueboy1894
- Re: Passing Dates to stored procedure - parameter headache.
- From: Alex Dybenko
- Passing Dates to stored procedure - parameter headache.
- Prev by Date: Re: Updating tables with a loop
- Next by Date: Re: Loop And Update?
- Previous by thread: Re: Passing Dates to stored procedure - parameter headache.
- Next by thread: Re: open pdf file stored as OLE object using VBA
- Index(es):
Relevant Pages
|