>Cetin,
>
>I am still having trouble with this and those I support are breathing hot and heavy for my soultion. My solution lies in your expertise with SQL statements. I will try to explain my situation again because in the message you sent me before there might have been some question as to what I need.
>
>I have one table in AS400. It has a field of document numbers and a field of descriptions. In the table for what ever reason the same document number can be listed many times each with a different portion of the description. So to get a complete picture of the document all the records of that number have to be brought together.
>
>Now my sistuation. I want to query the AS400 table by a word that is in the description. Say the word 'CLOTH'. I will get every record that the word 'CLOTH' is in. But I will not necessarly get all the records of each document since the word 'CLOTH' is not in every line of the description.
>
>So I need some way to pull up all the document records that have the word 'CLOTH' in any part of the description.
Let me see if I understood it right :
DocNum Description
------ -------------
1 Some description
2 In our excellent washers
1 Some more description
2 you can safely
3 Wear heavy clothing when
2 wash any type of clothes
3 leaving for arctics
If you put poor English a part your query should return ? :
DocNum Description
------ -------------
2 In our excellent washers
2 you can safely
2 wash any type of clothes
3 Wear heavy clothing when
3 leaving for arctics
SQL1 (Get DocNums) - don't know AS400 function support, guess supports upper() and maybe even some more easier ones :
select distinct DocNum from myTable where upper(Description) like '%CLOTH%'
SQL2 (Get a series of records) :
select * from myTable
Combine with a where :
select * from myTable ;
where DocNum in ;
( select distinct DocNum from myTable ;
where upper(Description) like '%CLOTH%' ) ;
order by DocNum
or
select * from myTable t1 ;
where exists ;
( select * from myTable t2 ;
where t1.DocNum = t2.DocNum and ;
upper(Description) like '%CLOTH%' ) ;
order by DocNum
lnResult = SQLExec(gnHandle,
"select * from myTable"+ ;
" where DocNum in "+;
" ( select distinct DocNum from myTable "+;
" where upper(Description) like '%CLOTH%' ) "+;
" order by DocNum", 'myCursor')
Cetin