Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 WHERE NOT

Author  Topic 

EricBHK
Starting Member

18 Posts

Posted - 2012-08-17 : 02:35:22
Hi !

I need to delete from an Access table those records that do NOT match my SQL search criteria.

I have the proper string for deleting in case criteria are met (see code below), but the invers situation simple won't work.

I have tried several thinsg such as :
WHERE NOT ... OR NOT
Keyword1 <> '" &ComboBox1.text & "'
WHERE EXISTS
... etc
but nothing seems to work.

Any suggestions ?


Thanks !




CopySql21 = "DELETE * FROM LiveSearch WHERE Keyword1 = '" & ComboBox1.Text & "' OR Keyword2 = '" & ComboBox1.Text & "' OR Keyword3 = '" & ComboBox1.Text & "' OR Keyword4 = '" & ComboBox1.Text & "' OR Keyword5 = '" & ComboBox1.Text & "' OR Keyword6 = '" & ComboBox1.Text & "' OR Keyword7 = '" & ComboBox1.Text & "' OR Keyword8 = '" & ComboBox1.Text & "' OR Keyword9 = '" & ComboBox1.Text & "' OR Keyword10 = '" & ComboBox1.Text & "' "

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-08-17 : 03:57:00
When you change to a not yoou also need to change or to and.
Alternatively get the PKs from your original query and use those for the delete.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

EricBHK
Starting Member

18 Posts

Posted - 2012-08-17 : 04:12:11
Hi nigelrivett,

Thanks for your answer. Unfortunatly, changing OR into AND was already one of the possibilities I examinded (see code below) and that failed.


CopySql21 = "DELETE * FROM LiveSearch WHERE Keyword1 <> '" & ComboBox1.Text & "' AND Keyword2 <> '" & ComboBox1.Text & "' AND Keyword3 <> '" & ComboBox1.Text & "' AND Keyword4 <> '" & ComboBox1.Text & "' AND Keyword5 <> '" & ComboBox1.Text & "' AND Keyword6 <> '" & ComboBox1.Text & "' AND Keyword7 <> '" & ComboBox1.Text & "' AND Keyword8 <> '" & ComboBox1.Text & "' AND Keyword9 <> '" & ComboBox1.Text & "' AND Keyword10 <> '" & ComboBox1.Text & "' "
Go to Top of Page

EricBHK
Starting Member

18 Posts

Posted - 2012-08-17 : 05:11:54
To the specific nature of this problem : I discovered that the SQL search is actually starting but that it is stopped (or at least pauzed) after the first row in my Access.datatable (given that this first row does not contain the value as selected in ComBoBox1.text !!!

So the real question is not so much related to the SQL script but rather on how to make the search persist through the entire Access.datatable ?????


Go to Top of Page
   

- Advertisement -