DataBase - Module for Date Filter for Stored Procedure

Asked By Brett Barry: Go Get Geek!
12-Nov-09 08:34 PM
Hello,

Can someone explain how I can create code to act as a parameter for a
stored procedure?

For example, in the following stored procedure:

sp_report ProfitAndLossStandard show Text, Label, Amount parameters
DateFrom = {d'yyyy-mm-dd'},
DateTo =  {d'yyyy-mm-dd'}, SummarizeColumnsBy = 'TotalOnly'

I would like to be able to generate results using parameters for each
quarter of the current calendar year.

The first quarter would make the parameter DateFrom = {d'2009-01-01'},
DateTo = {d'2009-03-31'}.

There would end up to be 4 queries, one for each quarter based on the
current year.

I am not sure if I am going about this right, but if anyone can explain
the best way to do this or provide useful links, it is much
appreciated.

Thanks!
SQL Server
(1)
EntityFilterFullNameWithChildren
(1)
CurrentDb.QueryDefs
(1)
Access 2007
(1)
JobEstimatesVsActualsDetail
(1)
ProfitAndLossStandard
(1)
Debug.Print
(1)
AmountDifferenceRevenue
(1)
  Tom van Stiphout replied to Brett Barry: Go Get Geek!
13-Nov-09 12:28 AM
Can you explain what version of Access and SQL Server you are using?
How are you connecting to SQL Server (odbc, adp, other)?

I am not familiar with this notation:
{d'yyyy-mm-dd'}
Where/how is this used?

Are you trying to open a form? Run a report? Get a recordset (dao or
ado)?

-Tom.
Microsoft Access MVP
  Brett Barry: Go Get Geek! replied to Tom van Stiphout
13-Nov-09 11:25 AM
I am using Access 2007 and a connection to a QuickBooks database via
an ODBC driver.


This is the date format for the parameter for filtering reports using
custom dates via DateFrom & DateTo. Otherwise, there is the parameter
DateMacro =3D 'LastCalendarQuarter' etc.
See http://doc.qodbc.com/qodbc/20/reports/sp_report_parameter_values0bbb.ht=
ml?sp_report_name_id=3D1



Before I had someone help me with a form to pull customer data and the
selection on the form was used as the parameter in the stored
procedure:

Private Sub Command7_Click()

Dim strSQL As String
strSQL =3D "sp_report JobEstimatesVsActualsDetail show Text, Label, " &
_
& _
=3D'" & _
Me.CustomerName & "',SummarizeColumnsBy =3D 'TotalOnly'"
Debug.Print strSQL
CurrentDb.QueryDefs("JobEstvsActuals").SQL =3D strSQL

End Sub

However, that was pulling the list of customers via a list box and
selection was done that way.


Perhaps on the form for this project, there are date pickers, one for
the date to and one for the date for and these dates are inserted in
the stored procedure, which is a make-table query to store the
results. Or, I could hard code the dates for each quarter, but there
would have to be some code to fill in the current year (yyyy). This is
eventually going to be used in a report.
  Tom van Stiphout replied to Brett Barry: Go Get Geek!
16-Nov-09 09:47 AM
The general technique of Command7_Click (what a terrible name for an
event procedure) is correct. Of course such code should be generalized
and put in a central location. You will need to find out how your
destination database wants date values delimited. Probably by
single-quotes.

-Tom.
Microsoft Access MVP
Create New Account
help
in a pass-through query via an ODBC connection. Pass-through "QueryName" has the following SQL: sp_report JobEstimatesVsActualsDetail show Text, Label, AmountEstCost, AmountActualCost, AmountDifferenceCost, AmountEstRevenue, AmountActualRevenue, AmountDifferenceRevenue parameters DateMacro = 'All', EntityFilterFullNameWithChildren = 'CustomerName', SummarizeColumnsBy = 'TotalOnly' and the following ODBC Connect Str property: ODBC;DSN = QuickBooks Data;SERVER = QODBC;OptimizerDBFolder = %UserProfile% \ QODBC Driver for QuickBooks \ Optimizer;OptimizerAllowDirtyReads = N;SyncFromOtherTables = N Thus, I would do not know the terminology) a customer name from my table Customers to the parameter EntityFilterFullNameWithChildren = 'x' where "x" is CustomerName from the Customers table. To simply this, let us start on to the forms and reports if that makes any sense. Thanks! Access Queries Discussions EntityFilterFullNameWithChildren (1) CurrentDb.QueryDefs (1) JobEstimatesVsActualsDetail (1) VB (1) OptimizerAllowDirtyReads (1) SyncFromOtherTables (1) You can use a little DAO code to update the SQL property of your p-t query. Assuming code in a form with a control lboCustomerName String strSQL = "sp_report JobEstimatesVsActualsDetail show Text, Label, " & _ Me.lboCustomerName & "', SummarizeColumnsBy = 'TotalOnly'" CurrentDb.QueryDefs("QueryName").SQL = strSQL - - Duane Hookom Microsoft Access MVP Due to my inexperience with forms, if you could sp_report JobEstimatesVsActualsDetail show Text, Label, " & _ & _ '" & _ Me.lboCustomerName & "', SummarizeColumnsBy = 'TotalOnly'" CurrentDb.QueryDefs("JobEstvsActuals").SQL = strSQL End Sub When I double-click on the customer in the list box, I
Connecting to SQL Server DataBase I connect my Access database to a SQL Server in two different ways: 1 with ADO such as: Dim theConnectionString theConnectionString = Driver = SQL Server; Server = Server \ TRUTIMEV3;Database = Intelligent;User ID = xxx;Password = xxx; Dim rec As ADODB.Recordset Set rec
proof DataBase https: / / mcp.microsoft.com / authenticate / validatemcp.aspx transcript: 944364 AccessCode: helloworld Access Discussions SQL Server 2008 R2 (1) SQL Server 2008 (1) SQL Server 2005 (1) Microsoft SQL Server Reporting Services (1) Regards Larry Linson Microsoft Office Access (1) Bing Microsoft SQL Server (1
Upgrade DB version from SQL Server 2000 to SQL Server 2005 DataBase Hi, I have a deployment with GP 9.0 SP3 with SQL Server 2000. I want to upgrade de Database engine to SQL Server 2005 in order to use SQL Server Analysis Services, SQL Server Integration Services and SQL