FunkyBunch
Instructor
Hello All,
I am currently using SQL 2005. The select statement I am trying to make will pull in the equipment id, a string literal describing the transfer.(Addition, Deletion, Transfer To, Transfer From), and the unit number the vehicle was transferred from/to.
This is the SQL i currently have:
*********************************************************
select access_equip_Fw,
(case
when (date_mounted_Equipment_removed_fw is null) and (access_equip_Fw in (select access_equip_Fw
from user_Defined20_Fw group by access_equip_fw having count(access_equip_fw)>1)) then 'Transfer From'
when Date_mounted_equipment_removed_fw is not null and (access_equip_Fw in (select access_equip_Fw
from user_Defined20_Fw group by access_equip_fw having count(access_equip_fw)>1)) then 'Transfer To'
when Date_Mounted_equipment_removed_fw is null and (access_equip_Fw in (select access_equip_Fw
from user_Defined20_Fw group by access_equip_fw having count(access_equip_fw)=1)) then 'Addition'
When (Archive_status_fw = 'A') then 'Deletion'
Else ''
end) AS "ADD/DELETE/TRANSFER"
from user_Defined20_fw
group by date_mounted_equipment_removed_fw, access_equip_Fw, archive_status_fw
**********************************************************
This is the data it returns:
100 Transfer From
1000 Addition
1002 Addition
1003 Addition
1004 Addition
1005 Addition
What i want to do is display a third column that tells where the piece of was transferred from/to. This is the select statment i have thus far:
******************************************************
(select vehicle_id_Fw
from user_defined20_fw
Where date_mounted_equipment_removed_Fw is not null and date_mounted_equipment_removed_fw <= (Select max(date_mounted_equipment_added_fw)
from user_Defined20_Fw
where access_equip_Fw in (select access_equip_Fw
from user_Defined20_Fw
group by access_equip_fw
having count(access_equip_fw)>1)))
*********************************************************
The data this select returns is the three units that equipment has been moved from:
10
8011
1189
Is there anyway (using the vehicle_id, a record #, equipment id, date removed, or date added.) that i can select the exact vehicle that a specific piece of equipment came from.
The Table i am using is a history table and holds the fields described above and creates a new record for every change. FX:
Equiment ID Vehicle ID Removed Added Record
5 1 09/10/07 01/12/05 1
5 5 NULL 09/10/07 2
I hope i provided enough information to recieve help, thanks everyone!
I am currently using SQL 2005. The select statement I am trying to make will pull in the equipment id, a string literal describing the transfer.(Addition, Deletion, Transfer To, Transfer From), and the unit number the vehicle was transferred from/to.
This is the SQL i currently have:
*********************************************************
select access_equip_Fw,
(case
when (date_mounted_Equipment_removed_fw is null) and (access_equip_Fw in (select access_equip_Fw
from user_Defined20_Fw group by access_equip_fw having count(access_equip_fw)>1)) then 'Transfer From'
when Date_mounted_equipment_removed_fw is not null and (access_equip_Fw in (select access_equip_Fw
from user_Defined20_Fw group by access_equip_fw having count(access_equip_fw)>1)) then 'Transfer To'
when Date_Mounted_equipment_removed_fw is null and (access_equip_Fw in (select access_equip_Fw
from user_Defined20_Fw group by access_equip_fw having count(access_equip_fw)=1)) then 'Addition'
When (Archive_status_fw = 'A') then 'Deletion'
Else ''
end) AS "ADD/DELETE/TRANSFER"
from user_Defined20_fw
group by date_mounted_equipment_removed_fw, access_equip_Fw, archive_status_fw
**********************************************************
This is the data it returns:
100 Transfer From
1000 Addition
1002 Addition
1003 Addition
1004 Addition
1005 Addition
What i want to do is display a third column that tells where the piece of was transferred from/to. This is the select statment i have thus far:
******************************************************
(select vehicle_id_Fw
from user_defined20_fw
Where date_mounted_equipment_removed_Fw is not null and date_mounted_equipment_removed_fw <= (Select max(date_mounted_equipment_added_fw)
from user_Defined20_Fw
where access_equip_Fw in (select access_equip_Fw
from user_Defined20_Fw
group by access_equip_fw
having count(access_equip_fw)>1)))
*********************************************************
The data this select returns is the three units that equipment has been moved from:
10
8011
1189
Is there anyway (using the vehicle_id, a record #, equipment id, date removed, or date added.) that i can select the exact vehicle that a specific piece of equipment came from.
The Table i am using is a history table and holds the fields described above and creates a new record for every change. FX:
Equiment ID Vehicle ID Removed Added Record
5 1 09/10/07 01/12/05 1
5 5 NULL 09/10/07 2
I hope i provided enough information to recieve help, thanks everyone!