View previous topic :: View next topic
|
Author |
Message |
alan_blore
New User
Joined: 01 Aug 2007 Posts: 50 Location: Hosur
|
|
|
|
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 |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Then there will be the adventure when there are more than 100 characters of pmodel data. . . .
d |
|
Back to top |
|
|
alan_blore
New User
Joined: 01 Aug 2007 Posts: 50 Location: Hosur
|
|
|
|
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 |
|
|
|