locked
How to search using the clause LIKE RRS feed

  • Question

  • User-388731848 posted

    I wantto search and retrieve the records from my Access database using LIKE clause. I have several parameters and each and every single of those parameters are within the LIKE clause. However when i don't assign the values to some parameters from my textboxes or dropdownlists, i still wantto retrieve data according to the rest of the parameters to which values are assigned.

    Heres is the sql statement i use;

    SELECT Kimlik, UNVANKODU, UNVANSIRA, IKINCIGOREV, IGONAYTARSAY, AKUNVAN, ADI, SOYADI, KIZSOYADI, SICIL, KADROKURUM, KADKURKOD, GECICIGOREV, GECICIGOREVKODU, ONAYMAKTARSAY, AYRILTAR, MEMURBASLAYIS, KURUMBASTAR, TCNO, ESNO, MEDENIHALI, CINSIYETI, DOGUMYERI, DOGUMTARIHI, BABAADI, ANNEADI, KANGURUBU, KROSOSHASTA, OGDURUMU, EVTEL, CEPTEL, EVADRESI, GELDIGIKURUM, GECGORYER, PARTTIMELISTESI, PARTTIMEYERI, KURSEGITIM, EMAIL, SENDIKA, Alan39 FROM CALISANLAR WHERE (ADI LIKE '%' & ? & '%' ) AND (SOYADI LIKE '%' & ? & '%' ) AND ( UNVANKODU LIKE '%' & ? & '%'  ) AND ( KADKURKOD   LIKE '%' & ? & '%')

    However this statement retrieve data, only if i assign values to all parameters. (When all the parameters were taken into consideration and values are assigned to all of them) When values are not assigned to some parameters from textboxes/dropdownlists, i wantto make a search according to the parameters to which their values are assigned. How can i do that on Access?

    Thanks in advance.

    Monday, March 30, 2009 5:32 AM

Answers

All replies

  • User1293829926 posted

     hi,

    use OR instead of AND clause. 

    Monday, March 30, 2009 7:32 AM
  • User97111691 posted

    infact me too gone thru the same situation. Access LIKE query wont retrun the desired results. one work around is like instead of using '%'  try using '*'. it worked in certain situations,but im not sure abt it.

    Monday, March 30, 2009 7:38 AM
  • User-388731848 posted
    That doesn't work either. By the way that query above works on Access Database environment and Query Builder of AccessDataSource object, however it doesn't, when i run the project, enter some values to textboxes and try to retrieve data.
    Monday, March 30, 2009 7:57 AM
  • User-388731848 posted
    I tried it, yet it doesn't work either.
    Monday, March 30, 2009 7:59 AM
  • User-821857111 posted

    You need optional parameters: http://www.mikesdotnetting.com/Article.aspx?ArticleID=68

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 30, 2009 2:09 PM
  • User-388731848 posted

    Thanks a lot, that helped.

    Tuesday, March 31, 2009 5:00 AM