IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

DB2-SQL Query help


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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
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

Moderator Emeritus


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

PostPosted: Tue Aug 24, 2010 9:54 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts Issue with EXEC CICS QUERY SECURITY c... CICS 6
Search our Forums:

Back to Top