@C:/temp/set_para.sql;
set pagesize 0
SPOOL c:/temp/Natp_query_DO_00300_res.txt
SELECT STA.primary_station_id AS "Primary Station ID", STA.fk_agency_code AS "Ag_Code",
STA.agency_name AS "Agency Name",STA.fips_hydrologic_unit_code AS "HUC",
STA.state_name AS "State Name",STA.county_name AS "County Name",STA.latitude AS "Latitude",
STA.longitude AS "Longitude",RES.fk_parameter_code AS "Parameter Code",RES.result_value AS "Result Value",
RES.fk_composite_statistic_code as "Composite Statistic Code",RES.fk_storet_result_remark_code AS "Result Remark Code",
SAM.start_date AS "Start Date",SAM.start_time AS "Start Time",SAM.end_date AS "End date",SAM.end_time AS "End Time",
SAM.sample_depth AS "Sample Depth",SAM.umk AS "UMK",SAM.replicate_number AS "Replicate Number",SAM.composite_grab_number AS "Composite Grab Number",
SAM.fk_composite_method_code AS "Composite Method Code",PAC.name AS "Primary Activity Category",SAC.name AS "Secondary Activity Category"
FROM kcs.lwlstation STA, storet_owner.result RES, storet_owner.sample SAM,storet_owner.prmry_scndry_actvty_combo2 com2,
storet_owner.primary_activity_category pac,storet_owner.secondary_activity_category sac
WHERE STA.computer_sequence_number = SAM.fk_computer_sequence_number
and RES.fk_sample_code_isn = sAM.sample_code_isn
and SAM.fk_prmy_scndy_combo2_code_isn = com2.code_isn (+)
and com2.fk_prmry_actvty_category_code = pac.code (+)
and com2.fk_scndry_actvty_category_code = sac.code (+)
and TO_CHAR(SAM.start_date, 'YYYY-MM-DD HH24:MI:SS')>='1990-01-01 00:00:00'
--and STA.state_name in (
--'Washington',
--'Maine',
--'Wisconsin',
--'Vermont',
--'Minnesota'
--					)
and RES.fk_parameter_code in (
'00300'					)
ORDER BY state_name, fk_Parameter_code, primary_station_id, start_date;
SPOOL OFF

-- PL/SQL procedure successfully completed.

@C:/temp/set_para.sql;
