MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Select Query Doubt

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
SAHANA
Beginner


Joined: 18 Jul 2007
Posts: 18
Topics: 5
Location: United Kingdom

PostPosted: Sun Nov 29, 2009 9:44 am    Post subject: Select Query Doubt Reply with quote

Hi All,

I have an input field I_PNO which comes from the Web and is stored in a table TAB1. I_PNO is a 10 digit alphanumeric field.

I have another host variable :PNO which is from a input flat file which is of the same length.

This is my select query in the code.

select * from tab1 where I_PNO =:PNO

This select query is coded assuming that only 10 digit part numbers would be entered from the web. But now the I_PNO can be 5 or 8 or 10 digit.

For ex: I_PNO = 12345. I will have to select all the records from the input file like this 12345%...I have to change the Select query now.

The :PNO can have values like 12345, 12345678ab, 1234567890.

So if the entered I_PNO from the web is 12345, i will have to select all the records which starts with 12345 from the flat file using the field :PNO.

Could you please let me know how should I change the select query now?

Thanks
Sahana
Back to top
View user's profile Send private message
papadi
Supermod


Joined: 20 Oct 2009
Posts: 594
Topics: 1

PostPosted: Sun Nov 29, 2009 4:49 pm    Post subject: Reply with quote

Quote:
I will have to select all the records from the input file like this 12345%
I believe you have answered your question. . .

Modify the value in the host variable before issuing the SELECT.
_________________
All the best,

di
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Mon Nov 30, 2009 9:07 am    Post subject: Reply with quote

Quote:
10 digit alphanumeric field.


well part of your problem is that you have such a poor foundation of DB2 vocabulary,
you can't ask questions properly or look up the answers yourself (if you are ever inclined to do so)

there is no such DB2 datatype as alphanumeric

now, are you saying that the trigger value will always need wildcards
or, is the data value in the qsam field an exact match to the DB2 column value?
Also, how is the datavalue captured during the web event stored?
as 0012345678, bb12345678, or 12345678bb? (where b = space)

if the former, then as di said, you have your answer. WHERE I_PNO LIKE :host_variable_padded_with_%
if the latter, then you want an exact match. WHERE I_PNO = :host_variable
so, what is the definition of the value of the field?
you will require different WHERE clause constructs.
As well as, since you are reading a qsam file,
this must be in BATCH,
what is your disposition of the SELECTed values?
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Mon Nov 30, 2009 11:20 am    Post subject: Reply with quote

dbzTHEdinosauer wrote:
if the former, then as di said, you have your answer. WHERE I_PNO LIKE :host_variable_padded_with_%
if the latter, then you want an exact match. WHERE I_PNO = :host_variable
so, what is the definition of the value of the field?
you will require different WHERE clause constructs.
As well as, since you are reading a qsam file,
this must be in BATCH,
what is your disposition of the SELECTed values?


dbz,

FWIW, I don't think you need different sql queries. It can be done in a single query itself. Untested code

Suhana,

Use this code

Code:

select * from tab1 where I_PNO LIKE :PNO


If your input has indeed leading spaces as well as trailing spaces and you would like to select if the string occurred any where you need to modify the host variable.

Code:

MOVE SPACES TO PNO                                     
INSPECT WEB-VAL TALLYING WS-TALLY FOR ALL SPACES       

EVALUATE TRUE                                         
     WHEN WS-TALLY = 1                                 
          STRING WEB-VAL   DELIMITED BY SPACE         
                 '%'       DELIMITED BY SIZE           
            INTO PNO                                   
     WHEN WS-TALLY > 1                                 
          STRING '%'       DELIMITED BY SIZE           
                 WEB-VAL   DELIMITED BY SPACE         
                 '%'       DELIMITED BY SIZE           
            INTO PNO                                   
     WHEN OTHER                                       
          MOVE WEB-VAL    TO PNO                       
END-EVALUATE                                           


Kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Mon Nov 30, 2009 12:44 pm    Post subject: Reply with quote

If the requirements are as one can assume based on what the TS has writen, I agree.
that means the qsam file is a fuzzy trigger/key.

but, what if the qsam file is an exact trigger/key? and the TS has not communicated that properly? Only his proposed solution?
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Mon Nov 30, 2009 1:16 pm    Post subject: Reply with quote

dbzTHEdinosauer wrote:
but, what if the qsam file is an exact trigger/key? and the TS has not communicated that properly? Only his proposed solution?


AFAIK, I think DB2 will work fine even when the key is full 10 bytes.

select * from tab1 where I_PNO LIKE '1234567890' will only fetch the record with 1234567890 as the PNO

kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group