Connecting Tech Pros Worldwide Forums | Help | Site Map

Parameters in a SQL Pass-through Query

Member
 
Join Date: Nov 2006
Posts: 78
#1: May 30 '07
I need to add the parameters [StartDate] and [EndDate] to an SQL Pass-through query. Currently my SQL is as follows:

Expand|Select|Wrap|Line Numbers
  1. SELECT POORDHDR_SQL.ord_no AS 'PO Number', TIMEDIM_SQL.BusinessDate AS 'PO Issue Date', TIMEDIM_SQL.Monthname AS 'PO Month', TIMEDIM_SQL_1.BusinessDate AS 'Requested Date', TIMEDIM_SQL_2.BusinessDate AS 'Promised Date', TIMEDIM_SQL_3.BusinessDate AS 'Receipt Date', APVENFIL_SQL.vend_no, APVENFIL_SQL.vend_name
  2. FROM DATA.dbo.APVENFIL_SQL APVENFIL_SQL, DATA.dbo.POORDHDR_SQL POORDHDR_SQL, DATA.dbo.POORDLIN_SQL POORDLIN_SQL, DATA.dbo.TIMEDIM_SQL TIMEDIM_SQL, DATA.dbo.TIMEDIM_SQL TIMEDIM_SQL_1, DATA.dbo.TIMEDIM_SQL TIMEDIM_SQL_2, DATA.dbo.TIMEDIM_SQL TIMEDIM_SQL_3
  3. WHERE POORDLIN_SQL.ord_no = POORDHDR_SQL.ord_no AND POORDHDR_SQL.ord_dt = TIMEDIM_SQL.MacolaDate AND POORDLIN_SQL.request_dt = TIMEDIM_SQL_1.MacolaDate AND POORDLIN_SQL.promise_dt = TIMEDIM_SQL_2.MacolaDate AND POORDLIN_SQL.receipt_dt = TIMEDIM_SQL_3.MacolaDate AND APVENFIL_SQL.vend_no = POORDHDR_SQL.vend_no
I have read that Access does not handle parameters in Pass-Through Queries in the same way as it handles parameters in other types of queries.....I have found this to be the case. I have tried to DECLARE @StartDate datetime, @EndDate datetime and adding TIMEDIM_SQL.BusinessDate Between [@StartDate] And [@EndDate] in the WHERE clause but I get syntax errors....

Newbie
 
Join Date: Apr 2007
Posts: 7
#2: May 31 '07

re: Parameters in a SQL Pass-through Query


There is more to it than this but this is an easy way if you are just staring out.

You will have to create a VBA sub (at the back end of a button or on some other form event - basically whatever it is you are using to start the query).

Declare your variables for start and end date + one to build the sql string for your query.

dim stDt as string, edDt as string, sqlSTR as string

Use an input box to ask the user for the dates.

Build the sql string:

sqlSTR = "SELECT ...... '" & stDt "' ... '" & edDt & "' ...."

Change the .SQL property of your query def to = the sqlSTR

CurrentDb.QueryDefs(qryNm).SQL = sqlSTR

Sorry for abreviated reply hope you can make sense.
Reply