Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 New here & to SQL

Author  Topic 

diveriter
Starting Member

3 Posts

Posted - 2005-07-27 : 09:45:26
Hi,
I'm pretty new to SQL & PL/SQL. I am running a select statement to pull a trucks with booms that have a Y or Z reason for repair w/the most recent date. I have that working, but can't figure out how to do the UPDATE to update the temp table. Any help would be appreciated.

David

Here's the script:

drop table davids_first_temp_table;
prompt "obtain vehicle information for all 'boom equipped' units"
create table davids_first_temp_table as
(select a.eq_equip_no, a.loc_assign_repr_loc, a.loc_assign_pm_loc,
a.loc_station_loc, a.loc_stored_loc, a.procst_proc_status,
a.eqtyp_equip_type
from eq_main@fatest a
where a.eqtyp_equip_type in
(select b.eqtyp_equip_type
from eq_subsys_detail@fatest b
where b.subprop_subsys_prop = 'BOOM MAKE'
and b.description is not null));

commit;
prompt "add additional columns to result table from above"
alter table davids_first_temp_table
add (unit_spec_sched number(3),
class_spec_sched number(3),
last_y_z_job varchar2(8));
commit;



prompt "locate unit-spec dielectric schedule"
update davids_first_temp_table a
set unit_spec_sched = (select b.description
from eq_subsys_detail@fatest b
where a.eqtyp_equip_type = b.eqtyp_equip_type
and b.subprop_subsys_prop = 'DIELECTRIC SCHED');

prompt "locate class-spec dielectric schedule"
update davids_first_temp_table a
set class_spec_sched = (select b.description
from eq_subsys_detail@fatest b
where a.eqtyp_equip_type = b.eqtyp_equip_type
and b.subprop_subsys_prop = 'DIELECTRIC SCHED');


prompt "locate last 'Y', 'Z' task and obtain date"
select a.eq_equip_no, decode(a.reas_reas_for_repair,'Y','1','Z','1','0'),
max(datetime_in_service)
from tsk_main@fatest a, job_main@fatest b
where decode(a.reas_reas_for_repair,'Y','1','Z','1','0') = '1'
and a.loc_work_order_loc = b.loc_work_order_loc
and a.work_order_yr = b.work_order_yr
and a.work_order_no = b.work_order_no
group by a.eq_equip_no,
decode(a.reas_reas_for_repair,'Y','1','Z','1','0');
commit;


prompt "update Y & Z data to dielectric schedule"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-07-27 : 09:53:17
Did you get any error?
Post table structures with some sample and expected data

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

diveriter
Starting Member

3 Posts

Posted - 2005-07-27 : 10:18:00
No errors, just gives me total count
SQL> select count(*) from davids_first_temp_table

COUNT(*)
----------
2180
I know there's 2180 trucks w/booms, but I need to know how many have a Y or Z reas_reas_for_repair and which is most resent to update the give a view of those eq_equip_no (truck #s) and the most recent Y or Z (but not both Y & Z)

hope that makes sense.

SQL> desc davids_first_temp_table
Name Null? Type
----------------------------------------- -------- ------------
EQ_EQUIP_NO VARCHAR2(12)
LOC_ASSIGN_REPR_LOC VARCHAR2(6)
LOC_ASSIGN_PM_LOC VARCHAR2(6)
LOC_STATION_LOC VARCHAR2(6)
LOC_STORED_LOC VARCHAR2(6)
PROCST_PROC_STATUS VARCHAR2(2)
EQTYP_EQUIP_TYPE VARCHAR2(15)
UNIT_SPEC_SCHED NUMBER(3)
CLASS_SPEC_SCHED NUMBER(3)
LAST_Y_Z_JOB VARCHAR2(8)
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-07-27 : 10:21:07
Don't mean to put a damper on this, but this looks like Oracle, and the folk in here are Microsoft SQL Server softies. There are bilingual people about, so someone may be able to help you, but you might want to seek out some Oracle-specific forums

Kristen
Go to Top of Page

diveriter
Starting Member

3 Posts

Posted - 2005-07-27 : 10:24:50
It is Oracle, but most of his scripts are writen in palin SQL. The senior analyst trys to keep the scripts as univserval as possible due to having Oracle, MS SQL & Access all under on roof.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-07-27 : 14:06:43
Plain SQL eh? Now there's an interesting concept! I've taken the liberty of colour coding the script you posted - I'm sure that my knowledge is not comprehensive, but as an indication the stuff in blue won't work as-is in SQL Server and the stuff in Red is just not recognised. Judging by my own methods, many here will want to just "plant" SQL from user querries into their database, see how it behaves, fiddle and then make suggestions. If it won't run for me [and I assume others too] then we tend to just move on to the next question.

drop table davids_first_temp_table;
prompt "obtain vehicle information for all 'boom equipped' units"
create table davids_first_temp_table as
(
select a.eq_equip_no, a.loc_assign_repr_loc, a.loc_assign_pm_loc,
a.loc_station_loc, a.loc_stored_loc, a.procst_proc_status,
a.eqtyp_equip_type
from eq_main@fatest a
where a.eqtyp_equip_type in
(select b.eqtyp_equip_type
from eq_subsys_detail@fatest b
where b.subprop_subsys_prop = 'BOOM MAKE'
and b.description is not null));

commit;
prompt "add additional columns to result table from above"
alter table davids_first_temp_table
add (unit_spec_sched number(3),
class_spec_sched number(3),
last_y_z_job varchar2(8));
commit;



prompt "locate unit-spec dielectric schedule"
update davids_first_temp_table a
set unit_spec_sched = (select b.description
from eq_subsys_detail@fatest b
where a.eqtyp_equip_type = b.eqtyp_equip_type
and b.subprop_subsys_prop = 'DIELECTRIC SCHED');

prompt "locate class-spec dielectric schedule"
update davids_first_temp_table a
set class_spec_sched = (select b.description
from eq_subsys_detail@fatest b
where a.eqtyp_equip_type = b.eqtyp_equip_type
and b.subprop_subsys_prop = 'DIELECTRIC SCHED');


prompt "locate last 'Y', 'Z' task and obtain date"
select a.eq_equip_no, decode(a.reas_reas_for_repair,'Y','1','Z','1','0'),
max(datetime_in_service)
from tsk_main@fatest a, job_main@fatest b
where decode(a.reas_reas_for_repair,'Y','1','Z','1','0') = '1'
and a.loc_work_order_loc = b.loc_work_order_loc
and a.work_order_yr = b.work_order_yr
and a.work_order_no = b.work_order_no

group by a.eq_equip_no,
decode(a.reas_reas_for_repair,'Y','1','Z','1','0');
commit;


prompt "update Y & Z data to dielectric schedule"

Kristen
Go to Top of Page
   

- Advertisement -