Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
from gltpgrbmy/ddacmsp
******************************************************************
jamief
January 19th, 2007, 11:51 AM
d chrcount s 8
d count s 8 0
d Myfile s 21
d sqlStmt s 250
c
c
c
c
c/exec sql
C+ Execute Immediate :sqlstmt
c/end-exec
c eval *inlr = *on
arrow483
January 19th, 2007, 01:04 PM
Take jaime's example but modify it to use the input variables:
myfile = %trim(P@Lib) + '/' + %trim(TestPF)
gcraill
January 20th, 2007, 12:56 AM
Nice example Jamie, 2 questions though (I am SQL noob)
[1] What does and when to use the Prepare statement ?
********************************************************************************
*****88
Select count(*), field1, field2, field3 from myfile
group by field1, field2, field3
having count(*) > 1
This would find matches on these three fields.
Programmatically you would open a cursor and fetch the results into a datastruct
ure of
count(*), field1, field2, field3
But if you must do it in RPG - this will do it -- kind of -- it will find record
s that are identical and have the same key unless there are other records that h
ave the same key and are not identical.
create two datastructures based on the file structure.
one of them should have a prefix such as h_
open the file as keyed
1. Read each record of the file
2. dow not eof
3. if the two datastructure's are equal
-- do whatever you want with the duplicated record
4. else
datastructure_h = datastructure
5 read next record
6 enddo
**********************************
Find out nth highest salary from emp table
SELECT DISTINCT (a.sal) FROM EMP A WHERE &N = (SELECT COUNT (DISTINCT (b.sal)) F
ROM EMP B WHERE a.sal<=b.sal);
For Eg:Enter value for n: 2
SAL
--------3700
**************************