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: 1278
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 Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


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