search different fields

Results 1 to 2 of 2

Thread: search different fields

  1. #1
    Join Date
    Dec 1969

    Default search different fields

    Hello,<BR>I have a query which I am searching on 4 different fields. This works well. What I have to do is output just that<BR>specific column info in which the search was found in. How do I code that? e.g <BR><BR>strSQLProvider = "SELECT distinct prov_cc, rate_code, cc_des, company, p_geo_lev_2, function, alloc_method, rate, acct,<BR>acct_desc, acct_lev_5, acct_lev_6, acct_lev_7, acct_lev_8, cc_lev_1, cc_lev_2, cc_lev_3, cc_lev_4, period "<BR>strSQLProvider = strSQLProvider & " FROM rate_code1 "<BR>strSQLProvider = strSQLProvider & " WHERE "<BR>strSQLProvider = strSQLProvider & " cc_lev_1 LIKE UPPER(&#039" & Form_p_cc_roll & "%&#039)"<BR>strSQLProvider = strSQLProvider & " OR cc_lev_2 LIKE UPPER(&#039" & Form_p_cc_roll & "%&#039)"<BR>strSQLProvider = strSQLProvider & " OR cc_lev_3 LIKE UPPER(&#039" & Form_p_cc_roll & "%&#039)"<BR>strSQLProvider = strSQLProvider & " OR cc_lev_4 LIKE UPPER(&#039" & Form_p_cc_roll & "%&#039)"<BR><BR>If the search was found in cc_lev_4, I want my heading to say...<BR><BR> Prov. CC Lev4<BR> -------------<BR> law<BR> finance<BR> controller<BR><BR>If the search was found on cc_lev_2, I want to have in my table say...<BR> Prov. CC Lev2<BR> ------------<BR> project mgmt<BR> money market<BR> etc.<BR><BR>Thanks in advance<BR>

  2. #2
    Steve Cimino Guest

    Default RE: search different fields

    Depending on how savy you are with SQL, you can use IF statements nearly identical to VB. You can also use the keyword RETURN to break out of the statement. You can also use the EXISTS keyword.<BR><BR>There are many different solutions, and the coding of them isn&#039t the easiest if you&#039re not familar with them, so go search these keywords in SQL Books Online. But it should look something like this (untested!!)<BR><BR>IF EXISTS (SELECT True FROM rate_code1 WHERE ...)<BR>BEGIN<BR>SELECT True<BR>RETURN<BR>END<BR><BR>BTW, it&#039s not really good programming practice to use underscores in your variable names. Just an opinion though.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts