I am new to SQL Stored Procedures. I use Crystal Reports 8.5 to run reports on a SQL2000 database.
The company's order records are stored in 2 tables: "Orders" and
"ArchivedOrders". I want to be able to create a SQL Stored Procedure that will prompt the Crystal Reports users for FromDate and ToDate parameters and allow them to retrieve data for date ranges that begin in the ArchivedOrders table and end in the Orders table. I have tried using the UNION feature in CR versions 9 and later, but since there are over 4 million records in these tables, it takes forever to process. Plus most of the users only have access to CR 8.5. I am hoping to find a more efficient method using a stored procedure to pull the order data from these 2 tables as well as data from linked fields in the Clients and Salesperson tables.
The field names and data types are identical in the 2 order tables, and the combined records in the 2 tables contain no duplicate records.
For example I would use the following fields to produce a sales by client report, that would include the clients' names and salespersons names from 2 other linked tables:
Orders.OrderNo int
Orders.AcctNo int
Orders.OrderDate varchar
Orders.SubtotalAmount money
Orders.TaxAmount money
Orders.TotalAmount money
ArchivedOrders.OrderNo int
ArchivedOrders.AcctNo int
ArchivedOrders.OrderDate varchar
ArchivedOrders.SubtotalAmount money
ArchivedOrders.TaxAmount money
ArchivedOrders.TotalAmount money
Clients.AcctNo int
Clients.Name varchar
Clients.SalespersonID int
Clients.SalesCommissionStartDate datetime
Salesperson.SalespersonID int
Salesperson.Name varchar
The OrderDate fields in the database are stored as varchar fields:
Jan 23 2006 12:15PM
Jan 23 2006 3:30PM
My first hurdle is how to convert these OrderDate varchar formats to a date format that can be used as from and to date parameters in the Crystal Report.
Can anyone help me get started with creating this Stored Procedure?
The company's order records are stored in 2 tables: "Orders" and
"ArchivedOrders". I want to be able to create a SQL Stored Procedure that will prompt the Crystal Reports users for FromDate and ToDate parameters and allow them to retrieve data for date ranges that begin in the ArchivedOrders table and end in the Orders table. I have tried using the UNION feature in CR versions 9 and later, but since there are over 4 million records in these tables, it takes forever to process. Plus most of the users only have access to CR 8.5. I am hoping to find a more efficient method using a stored procedure to pull the order data from these 2 tables as well as data from linked fields in the Clients and Salesperson tables.
The field names and data types are identical in the 2 order tables, and the combined records in the 2 tables contain no duplicate records.
For example I would use the following fields to produce a sales by client report, that would include the clients' names and salespersons names from 2 other linked tables:
Orders.OrderNo int
Orders.AcctNo int
Orders.OrderDate varchar
Orders.SubtotalAmount money
Orders.TaxAmount money
Orders.TotalAmount money
ArchivedOrders.OrderNo int
ArchivedOrders.AcctNo int
ArchivedOrders.OrderDate varchar
ArchivedOrders.SubtotalAmount money
ArchivedOrders.TaxAmount money
ArchivedOrders.TotalAmount money
Clients.AcctNo int
Clients.Name varchar
Clients.SalespersonID int
Clients.SalesCommissionStartDate datetime
Salesperson.SalespersonID int
Salesperson.Name varchar
The OrderDate fields in the database are stored as varchar fields:
Jan 23 2006 12:15PM
Jan 23 2006 3:30PM
My first hurdle is how to convert these OrderDate varchar formats to a date format that can be used as from and to date parameters in the Crystal Report.
Can anyone help me get started with creating this Stored Procedure?