Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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 query to fetch record which has only ... maxsubrat DB2 12 Mon Dec 11, 2017 5:03 pm
No new posts How to query MAXGENS of an existing P... Chuchulo Hatyzak JCL & VSAM 4 Wed Nov 22, 2017 10:23 pm
No new posts Native SQL Query kishpra DB2 1 Wed Nov 22, 2017 8:38 pm
No new posts Query on IEFBR14 with GDG Ashishpanpaliya JCL & VSAM 4 Tue Nov 07, 2017 8:34 pm
No new posts Query on XMITIP abdulrafi All Other Mainframe Topics 1 Wed Oct 25, 2017 6:54 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us