like command

hi again,i have the below simple line of sql code
local temp
temp=thisform.TextBox1.Value
SELECT costomer from customertable;
WHERE costomer_description LIKE temp

the command works perfectly and i get the results
in a new vfp window.
is there a way to change the command in such a way so that
i get the recno of the result.the reason is because there
is already a grid on the form and i guess that if i
had the recno from the select command i could focus that
particular record.seek command works on indexes so that
cant help me.after all i can use the % with my text in like
which saves me a lot of trouble.


Answer this question

like command

  • chrisuk2006

    Hi Billars,
    You could try something like :-

    Select ;
       customer, ;
       IIF(Seek(customer, "customertable"), Recno("customertable"), 0) ;
    From ;
       customertable ;
    Where ;
       customer_description Like temp 

    (Bare in mind, it's not portable ie - to SQL server etc.)

    HTH,

    Robbo.

  • Michal Malecki

    Hi Billaras,

    Yes - in order to do a SEEK, you need to have a INDEX.

    If you have a primary key (unique) (which all tables should have), I don't think you require the RECNO().

    As you can get back to the appropriate record because you *know* the unique key in the query. Tongue Tied

    Robbo.



  • jlang64

    For your information, locate do move the pointer. It does that in current workarea if no in clause is specified (in clause is nit suppported in all versions). If no match is found than positions the pointer to eof() ( and found() returns .f. ).

  • Efim

    Just one point, I did think to suggest SELECT x, y, RECNO() FROM z

    But tend to avoid that, as it will not work when you are selecting from multiple tables...

    Robbo.

  • TyTan

    thks for info guys,i guess it will be usefull in my future projects a lot
  • Kevin.Ji

    1)
    SELECT recno() from customertable ;
    WHERE costomer_description LIKE m.temp into array aResult
    if ( _Tally > 0 )
     go aResult in 'customertable'
    endif

    2) You don't need SQL at all.
    locate for like(m.temp, costomer_description)

    3) Since you don't have wildcards with like (also beware in VFP "like" is case sensitive - no set command I know of to make it a search case insensitive other than with conversion functions like upper(),lower()...)

    locate for costomer_description = m.temp in 'customertable'

    4) You don't need temporary variable temp.

    locate for costomer_description = thisform.TextBox1.Value in 'customertable'

    5) It isn't true that indexes can't help you. They can if you return primary key.

    select PrimaryKeyField from customertable ;
    WHERE costomer_description LIKE m.temp into array aResult
    if ( _Tally > 0 )
     =seek(aResult, 'customertable', 'PrimaryKeyTag' )
    endif

    6) Also check other functions like indexseek(), lookup(), at(), atc() ...  

  • Siddu

    hi robbo
    if i understood correct you mean that i must probably specify a index (of the 2 i have)as unique in order to avoid the error message i mentioned above.the database is created with vfp 9 and the indexes were in regular.when i try to change them to primary and candidate i get an error which says that uniqueness has been violated,which i suppose means that there are 2 or more same records.well the weird thing is that there arent!i even deleted all records of the table and still when i try to change an index from regular to primary i get the uniqueness violated error.i know im jumping from one problem to another (bad for a threat)but maybe that would be the source problem for the error i get in the seek command after the like






    E.T. Phone Home ...or ..E.T Send MMS Home

  • Deltoid

    and then i use go..

    well i thought of another way :
    SELECT costomer from customertable;
    WHERE costomer_description LIKE temp;
    INTO CURSOR csrTemp
    SET ORDER TO 2
    SET EXACT OFF
    SET NEAR ON
    SEEK costomer

    which would hopefully locate the data without even using recno at all.but i get an error msg of:table has no index order set..
    i have placed 2 indexes in the table and the costomer index is number 2(must i put first one primary,second candidate or something )
    i know that indexes work because i have in interactive event of a textbox
    STORE thisform.allpages.page1.ctextbox1.Value TO tempseek
    SET ORDER TO 2
    SET EXACT OFF
    SET NEAR ON
    SEEK tempseek
    thisform.Refresh()
    which works

    anyway that was just a thought,maybe with recno thing will be easier,any ideas

  • rankind

    grazie  cetinbasoz .i tried first way and it worked excellent..the problem with locate is that it doesnt move the record pointer to the spesific data in contrary to seek.so you must do that manually.anyway sql worked just fine so thks


  • like command