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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WHERE clause in SELECT does not work !? 2

Status
Not open for further replies.

mensudb

Programmer
Sep 2, 2004
13
US
Hello,

I have very simple query:
SELECT * FROM pordtxn WHERE slip=lslip INTO CURSOR ctmp
where lslip is local variable (numeric)

Every time this statement is executed I am getting the whole table PORDTXN. I have used debuger, and when this line has been executed I got the message telling me that filter is "skipped". What is causing this behavior?

Thanks

Mensud
 
Try exactly equals:

WHERE slip==lslip

boyd.gif

[sub]craig1442@mchsi.com[/sub][sup]
"Whom computers would destroy, they must first drive mad." - Anon​
[/sup]
 

Or if the slip and lslip are characters you may try:
Code:
SELECT * FROM pordtxn WHERE allt(slip)=allt(lslip) INTO CURSOR ctmp


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
HI

It is likely that your local variable lslip is not available when the SELECT is executed. That is possible, if you have set that value in some other method or event.

To make sure that it is available, I suggest you chechk with one of the following ways..
1. Insert a WAIT statement prior to SELECT statement and get the lSlip displayed... as.. WAIT WINDOW STR(lSlip)

OR

2. declare the lslip as PUBLIC for a trial run and see if that solves the issue.

Another possibility is that the field slip is not numeric and you are trying to compare a character type field to a numeric variable.

:)

____________________________________________
ramani - (Subramanian.G) :)
 
ramani,

if the variable wasn't in scope wouldn't VFP be giving an error such as "undefined"?

if the variable was not the same datatype wouldn't VFP be giving an error such as "datatype mismatch"?

boyd.gif

[sub]craig1442@mchsi.com[/sub][sup]
"Whom computers would destroy, they must first drive mad." - Anon​
[/sup]
 
It's probably something really simple. How about pasting the exact code into a code window, maybe with a few lines either side of the SELECT statement, along with a LIST STRUCTURE of the section of the table that shows the SLIP field.

You get a code window by enclosing your code with
Code:
 AND
tags, and making sure the "Process TGML" box at the bottom of the reply window is checked.

Mike Krausnick
Dublin, California
 
Hi,

Craig's advice (WHERE sli==lslip) was working.
Thanks for all others who replied on this question.

Mensud
 
Filter, seek and find behavior can be subtly different when SET EXACT is not ON or OFF as you may assume.
 
Craig;

PME4JI...

ramani,

if the variable wasn't in scope wouldn't VFP be giving an error such as "undefined"?

if the variable was not the same datatype wouldn't VFP be giving an error such as "datatype mismatch"?

I have seen this happen before. What I think is happening, is the missing variable is treated as a wildcard.

iow...

m.variable = .null.

SELECT cname, cadd1, ccity ;
FROM subscribers ;
WHERE nCustNo = m.variable ;
INTO CURSOR fred

is the same thing as

SELECT cname, cadd1, ccity ;
FROM subscribers ;
WHERE nCustNo = * ;
INTO CURSOR fred

In which case you'll get *all* the names.

Regards - Wayne
 
Wayne,


WHERE nCustNo = * ;
INTO CURSOR fred

In which case you'll get *all* the names


I see what you have in mind, but I don't think that's here. You wouild have to use the LIKE operator in order for wildcards to be recognised. Also, the SQL wildcards are % and _ rather than ? and *

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Mike;

Not by my machine right now. I understand about the asterisk. Replace the asterisk with a "null" or empty value and see what happens.

Regards - Wayne
 
Wayne,

Replace the asterisk with a "null" or empty value and see what happens.


I think the answer to that depends on the setting of SET ANSI. I'll have to try it when I get a moment.

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
NULL - doesn't display any records in VFP7 or VFP8 whether or not the Ansi is set on or off, so at least for me, it doesn't function as a wild card.

Also, there is a pretty sizeable distinction between a variable with a value of NULL and a variable that is UNDEFINED

...and when using an undefined variable in an sql, VFP will treat it as a column name and report an error SQL: Column "field | variable" is not found (Error 1806)

boyd.gif

 
Mike;

"NULL - doesn't display any records in VFP7 or VFP8"

I'm sure Craig's information is correct, my memory is prehistoric. I was thinking vers. 2.6 where this worked.

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top