on 2010 Feb 02 7:38 PM
It appears that iAnywhere 9.0.2 has some issues using NOT.
Here is the statement that’s working for me now:
SELECT DISTINCT contact.contact_id FROM contact WHERE ( (' ' + categories + ' ') LIKE '% 250% ') ORDER BY contact.contact_id; sQuery: SELECT DISTINCT contact.contact_id FROM contact WHERE ( (' ' + categories + ' ') LIKE '% 250% ') ORDER BY contact.contact_id; It returns 25 records
Here is the reverse of that one that I am trying to execute which finds almost all the records in the database but not the total amount -25 that are set to 250:
SELECT DISTINCT contact.contact_id FROM contact WHERE ( (categories NOT LIKE '% 250') AND (categories NOT LIKE ' %250% ') ) ORDER BY contact.contact_id;
I’ve found in SQL Interactive, even with very simple statements l can’t get the NOT to work no matter how I arrange the syntax.
I went to a SQL expert and he couldn’t figure it out and thought it was very strange.
I talked to one of the Sybase guys and he though it should work.
That's when he suggested this forum.
Anyone with any ideas?
Request clarification before answering.
Maybe it's you distinct which misleads you, e.g if you have data like this:
contact id, categories
1,250
1,30
2,250
The first statement (like 250) should result in 1 and 2 but your NOT statement will nevertheless return 1, because contact id 1 is in the set of category 250 but also in other sets, so also not in category 250... Dependent on the distinct the like and the not like result sets will not be just the opposite of each other.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Like Volker Barth said in a comment, "without more details" it's hard to tell... but, let's carry on anyway...
CREATE TABLE contact ( contact_id INTEGER NOT NULL DEFAULT AUTOINCREMENT PRIMARY KEY, categories VARCHAR ( 100 ) NOT NULL ); INSERT contact ( categories ) VALUES ( ' 250' ); INSERT contact ( categories ) VALUES ( ' 250 ' ); INSERT contact ( categories ) VALUES ( 'xxxxxx 250xxxxxx' ); INSERT contact ( categories ) VALUES ( ' 999' ); INSERT contact ( categories ) VALUES ( ' 999 ' ); INSERT contact ( categories ) VALUES ( 'xxxxxx 999xxxxxx' ); COMMIT; BEGIN SELECT DISTINCT contact.contact_id FROM contact WHERE ( (' ' + categories + ' ') LIKE '% 250% ') ORDER BY contact.contact_id; SELECT DISTINCT contact.contact_id FROM contact WHERE ( (' ' + categories + ' ') NOT LIKE '% 250% ') ORDER BY contact.contact_id; END;
Those two queries give these results...
contact_id 1 2 3 contact_id 4 5 6
You haven't showed us WHAT YOUR DATA ACTUALLY LOOKS LIKE, so we can't offer any opinions on whether the predicate ( (' ' + categories + ' ') NOT LIKE '% 250% ' is correct or not.
HOWEVER, the spaces look funky... the ' 's in (' ' + categories + ' ') might be redundant. JUST GUESSING... because I have NO IDEA WHAT YOUR DATA ACTUALLY LOOKS LIKE.
Hint... show us what your data actually looks like <g>... we really want to help.
Really.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
61 | |
8 | |
7 | |
6 | |
6 | |
4 | |
4 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.