Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL query runs but doesnt filter properly(VB6,SQL,Access DB)

Status
Not open for further replies.

LesMartin

Programmer
Sep 23, 2003
11
GB
Hi Guys,
Can anyone help me with my SQL here,
the recordset pulls a field called [field_name] but it must not = the var "progenyname" or the text values 'Unknown2' and 'Unknown'
The code below runs but still picks out the 'Unknown2' for some reason.
Any thoughts are very welcome.
Thanks
C

(&quot;SELECT * FROM table1 WHERE ([Field_name] <> 'Unknown2')And ([field_name] not like '*&quot; & Replace$(progenyname, &quot;'&quot;, &quot;''&quot;) & &quot;*')And ([Field_name] <> 'Unknown') And ([Field_sire] = &quot; & progenysire & &quot;) Or ([Field_dam] = &quot; & progenydam & &quot;)&quot;)

 
Hopefully this will do it:
Code:
SELECT * FROM table1
WHERE LEFT(Field_Name, 7) <> 'Unknown' AND
Field_Name NOT LIKE '*&quot; & Replace$(progenyname, &quot;'&quot;, &quot;''&quot;) & &quot;*' AND (Field_sire = &quot; & progenysire & &quot; OR Field_dam = &quot; & progenydam & &quot;)&quot;

Andy
&quot;Logic is invincible because in order to combat logic it is necessary to use logic.&quot; -- Pierre Boutroux
&quot;Why does my program keep showing error messages every time something goes wrong?&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top