473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to pass date parameter into Oracle SQL string in VBA

Hi folks

This is a bit of a long shot, but does anyone know how to pass a date variable into an Oralce SQL string in VBA. Here's an example of the string:

SQLCommand.CommandText = "SELECT T104F005_EMPLOYEE_NO, " & _
"to_char(T104F025_DATE_EFFECTIVE, 'DD/MM/YYYY'), " & _
"from DATABASE.T104_EMPLOYMENT_HISTORY " & _
"where T104F025_DATE_EFFECTIVE > '1-JUL-07' " & _
"order by T104F005_EMPLOYEE_NO "

The statement "where T104F025_DATE_EFFECTIVE > '1-JUL-07' " needs to be a variable date which is captured in another step in the code, then passed into the SQL string. Does anyone know how this is done? I've tried declaring a parameter (eg :DateEffective) and using that, but the SQL string wouldn't recognise it. Perhaps it has something to do with the fact that the SQL string is text surrounded by quotes, thereby treating the parameter as text rather than a true parameter? Any suggestions?

Cheers
Jan 9 '08 #1
1 13553
I just managed to figure out the way to pass a parameter to the SQL statement via VBA. It doesn't involve the standard Oracle parameter indicator, which is what was driving me mad. The secret is to use a question mark for each parameter, then set the parameter value in order of appearance in the SQL statement.

The following is the amended code:

.CommandText = "SELECT T104F005_EMPLOYEE_NO, " & _
"to_char(T104F025_DATE_EFFECTIVE, 'DD/MM/YYYY'), " & _
"from DATABASE.T104_EMPLOYMENT_HISTORY " & _
"where T104F025_DATE_EFFECTIVE BETWEEN ? AND ? " & _
"order by T104F005_EMPLOYEE_NO "
Set MyParameter = .CreateParameter("StartDate", adDBDate, dParamInput, , StartDate)
.Parameters.Append MyParameter ' this sets the value for the 1st parameter
Set MyParameter = .CreateParameter("EndDate", adDBDate, dParamInput, , EndDate)
.Parameters.Append MyParameter ' this sets the value for the 2nd parameter

StartDate and EndDate are date variables which have been set to certain dates (using the DD-MMM-YYYY format). MyParameter is a ADODB.Parameter variable.

Cheers
Jan 9 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Wayne Baswell | last post by:
I want to pass a date variable to a sql statement from Crystal Reports. The part of the query accepting the variables looks like: "Calendar_Date between To_Date('1-JUN-03','mm/dd/yy') and...
0
by: Raj | last post by:
hi, How to pass a Two Date parameter to a report at runtime using VB .NET 1. How do we pass multiple values eg. Startdate, EndDate to crystal reports parameter. 2. I have a report to...
2
by: Nelson Xu | last post by:
Hi All Does anyone knows how to pass an array from .net application to oracle stored procedure Thank you in advance Nelson
2
by: JMCN | last post by:
hi - i have created a passthrough query and have it automatically connect to the odbc and then on a separate form, i have the user type in the date parameters. however when i run the following...
0
by: Zlatko Matić | last post by:
Hi everybody! Recently I was struggling with client/server issues in MS Access/PostgreSQL combination. Although Access is intuitive and easy to use desktop database solution, many problems...
2
by: Greg Strong | last post by:
I'm experimenting with using Access 2k2 as a front end to Oracle Express. I am creating 10 tables using pass through DDL queries. The PROBLEM is the general format of the VB code WORKS on the 1st...
9
by: Greg Strong | last post by:
Hello All, What is the maximum length of an ODBC pass through query? Things work fine with the code except when I try to create a view which is pretty complex in Oracle. I'm using a DSN...
2
by: jmarr02s | last post by:
I am creating a Pass Through Query. Here is my code: SELECT MDSDBA_CINTAKE.RECVDATE, MDSDBA_CINTAKE.CMPSRC, Count(MDSDBA_CINTAKE.CMPSRC) AS CountOfCMPSRC FROM MDSDBA_CINTAKE WHERE...
5
by: cpnet | last post by:
I'm able to pass string parameters with no problems to a LocalReport being displayed by the ASP.NET ReportViewer control. However, my report also has a DateTime parameter. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.