Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Help with select statement
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9
Miscellaneous
Thread ID:
01335002
Message ID:
01335004
Views:
21
>I have a procedure that helps find certain events. I use a select statement to identify which events are to be searched. For example I need "Top Fuel" and it looks up anything with "Top Fuel" in the first part of the field.
>
>Problem is now the field could have any event buried inside it. So it may have "Torco Top Fuel" now instead. I am having some difficulty finding the string properly in a select statement. Here is what works for "easy" matches. I am trying to find out if SubStr() with an At() command or other VFP command can help me find the selection.
>
>
>
>
>Local yourselection, yourselectionwithlesscharacters, lcValue
>
>lcValue = 'Top Fuel'
>
>yourselection = '"' + Upper(Alltrim(lcValue)) +'%"'
>
>Select Dist Session,.F. As initialck ;
>	FROM icard ;
>	WHERE UPPER(Session) Like &yourselection ;
>	ORDER By Session Desc ;
>	INTO Cursor csrListSession Readwrite
>
>If _Tally > 0
>	** Call form method that checks or unchecks the list depending on which class is run
>	Thisform.check_qualifying_lists()
>Else
>	** WE DID NOT find any records so lets
>	** lower the character count to see if we get
>	** at hit on the first 11 characters
>	yourselectionwithlesscharacters = Left(Upper(Alltrim(lcValue)),11)
>	yourselection = '"' + yourselectionwithlesscharacters +'%"'
>	Select Dist Session,.F. As initialck ;
>		FROM icard ;
>		WHERE Upper(Session) Like &yourselection ;
>		ORDER By Session Desc ;
>		INTO Cursor csrListSession Readwrite
>	
>	If _Tally > 0
>		* Call form method that checks or unchecks the list depending on which class is run
>		Thisform.check_qualifying_lists()
>
>	Else
>
>
>		** Now one last attempt at 5 characters
>		** if this does not work then give up
>		yourselection = LEFT(Upper(Alltrim(lcValue)),5)
>
>                                         * this is where I need help with finding any records that Contain Top Fuel anywhere in the text.
>
>		Select Dist Session,.F. As initialck ;
>			FROM icard ;
>			WHERE SUBSTR(Upper(Session),AT(yourselection,Upper(Session)),LEN(yourselection)) = yourselection ;
>			ORDER By Session Desc ;
>			INTO Cursor csrListSession Readwrite
>		If _Tally > 0
>			BROWSE
>			* Call form method that checks or unchecks the list depending on which class is run
>			* Thisform.check_qualifying_lists()
>
>		Else
>
>			** nothing found let them know
>			MESSAGEBOX("Sorry, No Records Found for this Class",0,"NO Records Exist")
>
>		Endif
>	Endif
>Endif
>
>
>
>
>
>The last select is where I need the help. It returns way too many records because it is not constructed properly.

Firstly, you could use SCAN loop for your task. Speed will be roughly the same, but your code could be more readable. Secondly, you could just use AT(...)>0 to find out if searched phrase is within the string, i.e. you don't need in SUBSTR, etc.
Edward Pikman
Independent Consultant
Previous
Reply
Map
View

Click here to load this message in the networking platform