Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

DB2-SQL Query help

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
alan_blore

New User


Joined: 01 Aug 2007
Posts: 50
Location: Hosur

PostPosted: Tue Aug 24, 2010 2:58 pm    Post subject: DB2-SQL Query help
Reply with quote

I m stuck up with this part in SQL. I cannot find a query to get the below result:

There is a table with a character field of length 100 called PMODELS. This field has different product models separated by a single space.

Example: Velow are 2 records

Part PMODELS
0204567 737 737-291A 737-322 737-522 747-422 757-222 767-322ER
0205666 737-322 737-522

where 737, 737-291A, 737-322, 737-522,etc... are Product models in which the part can be used.

I need to exclude those records which contains only 737 in PMODELS field... meaning, if the models are only 737's then it should be excluded. So, from the above rows, 0205666 should be excluded.

I m not sure if this is possible in SQL... but pls have a look and let me know a solution....

Thanks!
Back to top
View user's profile Send private message

GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Tue Aug 24, 2010 6:51 pm    Post subject:
Reply with quote

a field with a list of .... is a direct mistake against decent modelling, causing this kind of difficult SQLs. In fact having such a list means you should be testing the contents in a program rather than in SQL

but if you really want to and if the delimiter is never two spaces :
Step1) remove spaces at the end => strip(pmodels)
Step2) add a space in the beginning of pmodels => concat(' ',strip(pmodels))
Step3) replace all ' 737' => replace(concat(' ',strip(pmodels)),' 737','xxxx'))
Step4) see if there are still spaces in the string : where posstr(replace(concat(' ',strip(pmodels)),' 737','xxxx')),' ') > 0
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Tue Aug 24, 2010 9:54 pm    Post subject: Reply to: DB2-SQL Query help
Reply with quote

Then there will be the adventure when there are more than 100 characters of pmodel data. . . . icon_wink.gif

d
Back to top
View user's profile Send private message
alan_blore

New User


Joined: 01 Aug 2007
Posts: 50
Location: Hosur

PostPosted: Thu Sep 02, 2010 2:26 am    Post subject:
Reply with quote

Apologize for the delayed reply.

Thanks for your response too

I guess since the complexity in handling using Queries was more, we were adviced here to do it thru program, as said by Guy :-) and we did it using SAS.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Omegamon for DB2 query ashek15 DB2 0 Wed Feb 15, 2017 11:25 am
No new posts Query on DB2 WLM stored procedures ashek15 DB2 8 Sun Feb 12, 2017 11:13 pm
No new posts GETMAIN/FREEMAIN query Suja.Sai CICS 9 Tue Jan 31, 2017 12:01 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us