HELP!!! is the lag function?
Why I am not getting the right results here when I do the insert into the table, I got the right results when I run the select statment alone BUT not when I try to insert the results in the table. I am in the process of writing a PL\SQL package and I stuck here, I try to put this is a cursor, It did not work either same problem right results in the select satement of the cursor BUT no when I uodate the table.
INSERT INTO TEMP_IND
(
temp_pidm,
temp_term_code,
temp_bldg_code,
temp_room_number,
temp_indicator
)
SELECT
s.szslife_pidm,
s.szslife_slrrasg_term_code,
s.szslife_building_code,
s.szslife_room_number,
DECODE (lag(srr.repeat_room_number)
over (PARTITION BY srr.repaat_bldg_code
,srr.repeat_room_number
ORDER BY srr.repeat_term_code
)
,'N', NULL
,srr.repeat_room_number,'Y'
,'N'
) indicator2
FROM SZSLIFE_REPEAT_ROOM srr
,SZSLIFE s
WHERE srr.repeat_pidm = s.szslife_pidm
AND srr.repaat_bldg_code = s.szslife_building_code
AND srr.repeat_room_number = s.szslife_room_number
AND srr.repeat_term_code = s.szslife_slrrasg_term_code
--AND szslife_pidm = 1862
GROUP BY
s.szslife_pidm,
s.szslife_slrrasg_term_code,
s.szslife_building_code,
s.szslife_room_number,
srr.repaat_bldg_code,
srr.repeat_room_number,
srr.repeat_term_code
right results
1862 200290 BLA 003 N
1862 200310 BLA 003 Y
1862 200390 BLA 207 N
1862 200410 BLA 207 Y
1862 200590 SMI 216 N
1862 200610 SMI 216 Y
1862 200490 UNI 4 N
1862 200510 UNI 4 Y
when I inserted in the table it insert all the rows with a Y