Re: ADP/SQL Data Selection Criteria in a Stored Procedure
From: Gregory A. Larsen (greg.larsen_at_netzero.com)
Date: 08/31/04
- Next message: Bill Nguyen: "SQL Syntax - CAST data type conversion & format"
- Previous message: Larry Woods: "Any way to get the equiv. of Q Anaylzer 'row(s) affected' in SQL?"
- In reply to: Ghulam: "ADP/SQL Data Selection Criteria in a Stored Procedure"
- Next in thread: Ghulam: "Re: ADP/SQL Data Selection Criteria in a Stored Procedure"
- Reply: Ghulam: "Re: ADP/SQL Data Selection Criteria in a Stored Procedure"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 31 Aug 2004 09:26:05 -0700
Possibly you can use a UNION with a subquery to get the results. How about
something like this:
set nocount on
create table table1 (Client_Id int, DateEntered datetime, Employee_ID int)
insert into table1 values(23376,'1/9/2004',128)
insert into table1 values(23376,'1/8/2004',30)
insert into table1 values(23379,'1/6/2004',15)
insert into table1 values(23377,'1/6/2004',15)
insert into table1 values(23380,'12/31/2003',15)
insert into table1 values(23377,'12/31/2003',15)
create table table2 (Client_Id int, DateEntered datetime, Employee_ID int)
insert into table2 values(23376,'7/20/2004',30)
insert into table2 values(23376,'7/12/2004',30)
insert into table2 values(23376,'7/6/2004',30)
insert into table2 values(23376,'7/4/2004',30)
insert into table2 values(23377,'7/6/2004',30)
select * from
(
select client_id, dateentered, employee_id, 'table1' as record_source from
table1
union
select client_id, dateentered, employee_id, 'table2' as record_source from
table2
) a
where a.dateentered = (select top 1 dateentered from
(
select client_id, dateentered, employee_id, 'table1' as
record_source from table1
union
select client_id, dateentered, employee_id, 'table2' as
record_source from table2
) b
where a.client_id = b.client_id
order by dateentered desc)
and a.client_id = (select top 1 client_id from
(
select client_id, dateentered, employee_id, 'table1' as
record_source from table1
union
select client_id, dateentered, employee_id, 'table2' as
record_source from table2
) b
where a.client_id = b.client_id
order by dateentered desc)
drop table table1
drop table table2
-- ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- - Need SQL Server Examples check out my website http://www.geocities.com/sqlserverexamples "Ghulam" <a1besw@ccbq.org> wrote in message news:6f78616e.0408310727.5d99cf62@posting.google.com... > I am using ADP front end and SQL on the back end. I want to run a > report based on these 2 tables. > > Table1 Data: > > Client Id Date Employee ID Record Source > > 23376 1/9/2004 128 Table1 > 23376 1/8/2004 30 Table1 > 23379 1/6/2004 15 Table1 > 23377 1/6/2004 15 Table1 > 23380 12/31/2003 15 Table1 > 23377 12/31/2003 15 Table1 > > > Table 2 Data: > > Client Id Date Employee ID Record Source > > 23376 7/20/2004 30 Table2 > 23376 7/12/2004 30 Table2 > 23376 7/6/2004 30 Table2 > 23376 7/4/2004 30 Table2 > 23377 7/6/2004 30 Table2 > > > Now I need to select the data from both Tables for the report based on > this criteria: > > Select Only one record (i.e. the same Client Id with the latest date). > That is my report row source should look like this: > > Final row source: > > Client Id Date Employee ID Record Source > > 23376 7/20/2004 30 Table2 > 23377 7/6/2004 30 Table2 > 23379 1/6/2004 15 Table1 > 23380 12/31/2003 15 Table1 > > > First I thought to create a Temporary File in a SP and append data > from Table1 and Table2 but I don't know how to populate the desired > result in SP and return as a report row source in ADP. > > But If I need to run everything in ADP, what will be my best approach? > Create a Hard Coded Temporary file, append data from Table1 and Table2 > and Populate the report result and run the report. But Only problem I > think what will happen if 2 users run the same report at the same time > since the report row source is a hard coded temporary file. > > Any suggestion or help with coding will be appreciated. Thanks
- Next message: Bill Nguyen: "SQL Syntax - CAST data type conversion & format"
- Previous message: Larry Woods: "Any way to get the equiv. of Q Anaylzer 'row(s) affected' in SQL?"
- In reply to: Ghulam: "ADP/SQL Data Selection Criteria in a Stored Procedure"
- Next in thread: Ghulam: "Re: ADP/SQL Data Selection Criteria in a Stored Procedure"
- Reply: Ghulam: "Re: ADP/SQL Data Selection Criteria in a Stored Procedure"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|