|
| |
|
|
lu lu
Posts: 418 From: wpg, mb Status: offline
|
AND / OR paramaters - 9/18/2002 16:27:43
In the Drw i can select AND or OR, these are the search fields: ID company_name city province phone_number fax_number line_of_business number_of_employees sales_volume occupation esi_rep My problem: if i set occupation to OR, i can' t find out which esi_rep is working on what occupation, IF i set occuaption to AND, i can' t just type in an occupation for search without using another field name in the search. I would like to do both. How would i use occupation on its own for searching and still use occuaption with esi_rep, to display records that esi_rep is associated with?
|
|
|
|
hhammash
Posts: 1064 Joined: 8/19/2002 Status: offline
|
RE: AND / OR paramaters - 9/18/2002 16:41:03
Hi lulu, Create a form (Can be HTML also), put in the form all the fields. Give the fields the same names of the DRW (Basically the database fields). Then put the default value in each field as " %" with the quotation marks. Then post the form to the DRW. In this case the DRW will neglect the empty fields. If you have in your fields a combination or Text and numeric, put the default values of all the fields to be the same field name: Example: FaxNumber , default value should be FaxNumber Do this to all fields. Only if you have a combination of text and numeric, otherwise put % as a default value to all fields. Regards Hisham
|
|
|
|
lu lu
Posts: 418 From: wpg, mb Status: offline
|
RE: AND / OR paramaters - 9/18/2002 16:58:06
since i have numeric and text field i set the deafults to be the field name of that field and the DRW results isn' t working, well it is displaying all records from the db regardless of query or not, when i try to query teh db nothing happens and the same result list is displayed. Example all db records are being displayed in teh DRW query results section, is i query a record that has a value unlike all the other records, them the DRW results still displayes all records from the db. What else is there to try? maybe i' m miss understanding, i have create the form and assigned names to the fields. I post the form to the database. I created a DRW to query the table and display records found. This is the critera fields that i' m using: ID company_name city province phone_number fax_number line_of_business number_of_employees sales_volume occupation esi_rep i would like to search by occupation only to display records of all occupations matching the search (which is the OR). I would ALSO like to search by occupation and esi_rep, to display all records containing those two search critera (which is the AND). hope this better explains myself
< Message edited by lu lu -- 9/17/2002 5:26:33 PM >
|
|
|
|
hhammash
Posts: 1064 Joined: 8/19/2002 Status: offline
|
RE: AND / OR paramaters - 9/18/2002 17:27:48
Hi lulu look at this http://www.fmhs.uaeu.ac.ae/nml/Forums/NorthWind/Search.htm I forgot to tell you. In the DRW use the criteria button. Then add all the fields that are in the search form, all of them with And and Begins With. Then put the default as I told you. Regards Hisham
< Message edited by hhammash -- 9/18/2002 3:50:25 PM >
|
|
|
|
hhammash
Posts: 1064 Joined: 8/19/2002 Status: offline
|
RE: AND / OR paramaters - 9/18/2002 17:32:58
Hi, Look at the SQL of my DRW fp_sQry=" SELECT * FROM Customers WHERE (ContactTitle LIKE ' ::ContactTitle::%' AND City LIKE ' ::City::%' AND Country LIKE ' ::Country::%' )" fp_sDefault=" ContactTitle=%&City=%&Country=%" fp_sNoRecords=" <tr><td colspan=11 align=left width=" " 100%" " >No records returned.</td></tr>" fp_sDataConn=" Northwind" Hisham
|
|
|
|
lu lu
Posts: 418 From: wpg, mb Status: offline
|
RE: AND / OR paramaters - 9/19/2002 10:07:45
quote:
Then put the default value in each field as " %" with the quotation marks. when i use the quotes my sql look totaly different than the one you displayed and i get an error of invalid character pointing at " %" , i think you ment to say with OUT the quotes, but then why did you use the quotes in the first place. quote:
put the default values of all the fields to be the same field name so if i have 30 fields they should all have the same field name, that doesn' t make sense? I guess i need to take that sentence as " put the defaults of all the fields to be the same field name as that particular field." quote:
Then add all the fields that are in the search form, all of them with And and Begins With were you unaware that i have an ID field and other number fields. can any one else help me?
< Message edited by lu lu -- 9/18/2002 10:12:35 AM >
|
|
|
|
rdouglass
Posts: 9224 From: Biddeford, ME USA Status: offline
|
RE: AND / OR paramaters - 9/19/2002 10:26:28
I have used a DRW hack (quite a severe hack) and if you' d like, you can use it and I' ll help you thru it. It basically involves checking each search box for any data, then building the SQL string based on valid inputs, then passing the SQL string to a hacked DRW. There is an example posted here. It is for a simple knowledgebase that I set up on our Intranet. It uses 2 text fields (Keywords and Body) and 3 dropdowns (Cat1, Cat2, and Cat3). It checks each field submitted for entries. If there is something in the field, it adds it to the SQL string; if not, it ignores it. Your welcome to use this and adapt it to your scenario; I' ll give you pointers along the way if you' d like....
|
|
|
|
lu lu
Posts: 418 From: wpg, mb Status: offline
|
RE: AND / OR paramaters - 9/19/2002 11:17:08
Every field in the db has a value. My problem exists when i use the DRW to to query the database and display the records. I have a bunch of fields in the db but only a hand full are used to query the db, these are the hand full: ID (unique autonumber) company_name (text) city (text) province (text) phone_number (text) fax_number (text) line_of_business (text) number_of_employees (text) sales_volume (text) occupation (text) esi_rep (text) In the Critera part of the DRW i have the following: Field---Comparision---Value---AND/OR ID---equals---[ID]---OR company_name---contains---[company_name]---OR city---contains---[city]---OR province---contains---[province]---OR phone_number---equals---[phone_number]---OR fax_number---equals---[fax_number]---OR line_of_business---contains---[line_of_business]---OR number_of_employees---Not less than---[number_of_employees]---OR sales_volume---Not less than---[sales_volume]---OR occupation---contains---[occupation]---OR esi_rep---contains---[esi_rep]---OR And under the " Defaults" button, for the input parameters, i have a default value of NULL for every field. When saved and test it works great for single search queries, that is, if i only search for a record using only one of the search fields: ID (unique autonumber) company_name (text) city (text) province (text) phone_number (text) fax_number (text) line_of_business (text) number_of_employees (text) sales_volume (text) occupation (text) esi_rep (text) If i want to find a record that contains a specific esi_rep AND a specific occupation, meaning i use those two search field for the query, it does not display the record with fitting both critera. I understand this will not work because i am using the OR operative for occupation & esi_rep. So how am i able to search only by occuaption (to display all the containing the occupation) AND, if i would like, to also search for a record in a specific occupation that also contains a specific esi_rep ?
< Message edited by lu lu -- 9/18/2002 11:20:30 AM >
|
|
|
|
rdouglass
Posts: 9224 From: Biddeford, ME USA Status: offline
|
RE: AND / OR paramaters - 9/19/2002 11:28:32
The example code I posted does what I think you' re asking for. You definitely would need to adapt it for your environment and SQL statements. Have you looked at the link I provided above? ...and if so, does it make any sense to you? Maybe I should explain more. We' ll take the first two sections: Dim TechTipQueryString, KyWdStr, Cat1Str, Cat2Str, Cat3Str, Body
TechTipQueryString = " " (DIM and initialize variables. I used 5 fields but you would need more.) If Request(" Keywords" ) = " " then
TechTipQueryString = " " (If KEYWORDS field is blank, leave the variable alone) else
TechTipQueryString = " (Keywords LIKE ' %::Keywords::%' )" (If KEYWORDS has something in it, add it to the query) end if
If Request(" CategoryDesc1" ) <> " None" then (If CATEGORYDESC1 has something other than " None" , include it in the query) If TechTipQueryString = " " then
TechTipQueryString = " (Cat1 LIKE ' %::CategoryDesc1::%' OR Cat2 LIKE ' %::CategoryDesc1::%' OR Cat3 LIKE ' %::CategoryDesc1::%' )" (If query has nothing in it yet, add CATEGORYDESC1 to it) else
TechTipQueryString = TechTipQueryString & " AND (Cat1 LIKE ' %::CategoryDesc1::%' OR Cat2 LIKE ' %::CategoryDesc1::%' OR Cat3 LIKE ' %::CategoryDesc1::%' )" (If there was already something in the query, need to put " AND" in before adding to query) end if
end if Continue on with all our other fields checking for contents of the field as well as contents of TechTipQueryString...... Then we pass the variable ' TechTipQueryString' to the DRW like this: fp_sQry=" SELECT * FROM Main WHERE (" &TechTipQueryString&" )" This does work and will do what you want (or at least how I understand what you want). Does this help at all???
< Message edited by rdouglass -- 9/18/2002 11:30:16 AM >
|
|
|
|
lu lu
Posts: 418 From: wpg, mb Status: offline
|
RE: AND / OR paramaters - 9/19/2002 12:17:27
Ok I think i somewhat understand what going on in the code you presented. So am i on the right path? so with If Request(" CategoryDesc1" ) <> " None" then If TechTipQueryString = " " then TechTipQueryString = " (Cat1 LIKE ' %::CategoryDesc1::%' OR Cat2 LIKE ' %::CategoryDesc1::%' OR Cat3 LIKE ' %::CategoryDesc1::%' )" else TechTipQueryString = TechTipQueryString & " AND (Cat1 LIKE ' %::CategoryDesc1::%' OR Cat2 LIKE ' %::CategoryDesc1::%' OR Cat3 LIKE ' %::CategoryDesc1::%' )" end if end if I would create the above for every field name used in the query, so my first one would be: If Request(" ID" ) <> " None" then If TechTipQueryString = " " then TechTipQueryString = " (ID LIKE ' %::ID::%' OR company_name LIKE ' %::ID::%' OR city LIKE ' %::ID::%' OR province LIKE ' %::ID::%' OR phone_number LIKE ' %::ID::% OR fax_number LIKE ' %::ID::%' OR line_of_business LIKE ' %::ID::%' OR number_of_employees LIKE ' %::ID::%' OR sales_volume LIKE ' %::ID::%' OR occupation LIKE ' %::ID::%' OR esi_representative LIKE ' %::ID::%' )" else TechTipQueryString = TechTipQueryString & " AND (ID LIKE ' %::ID::%' OR company_name LIKE ' %::ID::%' OR city LIKE ' %::ID::%' OR province LIKE ' %::ID::%' OR phone_number LIKE ' %::ID::% OR fax_number LIKE ' %::ID::%' OR line_of_business LIKE ' %::ID::%' OR number_of_employees LIKE ' %::ID::%' OR sales_volume LIKE ' %::ID::%' OR occupation LIKE ' %::ID::%' OR esi_representative LIKE ' %::ID::%' )" end if end if so next i' d have Request(" company_name" ): If Request(" company_name" ) <> " None" then If TechTipQueryString = " " then TechTipQueryString = " (ID LIKE ' %::company_name::%' OR company_name LIKE ' %::company_name::%' OR city LIKE ' %::company_name::%' OR province LIKE ' %::company_name::%' OR phone_number LIKE ' %::company_name::% OR fax_number LIKE ' %::company_name::%' OR line_of_business LIKE ' %::company_name::%' OR number_of_employees LIKE ' %::company_name::%' OR sales_volume LIKE ' %::company_name::%' OR occupation LIKE ' %::company_name::%' OR esi_representative LIKE ' %::company_name::%' )" else TechTipQueryString = TechTipQueryString & " AND (ID LIKE ' %::company_name::%' OR company_name LIKE ' %::company_name::%' OR city LIKE ' %::company_name::%' OR province LIKE ' %::company_name::%' OR phone_number LIKE ' %::company_name::% OR fax_number LIKE ' %::company_name::%' OR line_of_business LIKE ' %::company_name::%' OR number_of_employees LIKE ' %::company_name::%' OR sales_volume LIKE ' %::company_name::%' OR occupation LIKE ' %::company_name::%' OR esi_representative LIKE ' %::company_name::%' )" end if end if and so on. Is this correct?
< Message edited by lu lu -- 9/18/2002 12:24:24 PM >
|
|
|
|
Long Island Lune
Posts: 2340 Joined: 6/8/2002 From: New York Status: offline
|
RE: AND / OR paramaters - 9/19/2002 12:58:56
lu lu, I thought you only wanted to search by occupation??? Also, ID LIKE ' %::ID::% ??? Interesting.... So your saying that your looking for an ID like 47, but you' ll except 147, 478, 1478??? Confusing post... [:j]
_____________________________
|
|
|
|
lu lu
Posts: 418 From: wpg, mb Status: offline
|
RE: AND / OR paramaters - 9/19/2002 13:07:47
I see... should... ID LIKE ' %::ID::%' ...be ' #::ID::#' ? aspects implemented (what other parts need to be changed to it to workl? AND THANK YOU sooo much for helping me get through this, it is so appreciated.):
< Message edited by lu lu -- 9/18/2002 3:04:36 PM >
|
|
|
|
lu lu
Posts: 418 From: wpg, mb Status: offline
|
RE: AND / OR paramaters - 9/19/2002 14:19:38
ok i implemented those changes and now i' m trying to over come this database results error: Too few parameters. Expected 1.
< Message edited by lu lu -- 9/18/2002 5:21:23 PM >
|
|
|
|
lu lu
Posts: 418 From: wpg, mb Status: offline
|
RE: AND / OR paramaters - 9/19/2002 15:24:36
I caught that typo about 5 minutes after i posted, but i' m still getting the database results error: Too few parameters. Expected 1. i tried to run a query any way with just putting 2 in the ID field for query and i recieved this database result error: Syntax error (missing operator) in query expression ' ((ID EQUALS 2))' . I don' t understand that. I also looked up the first error: http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q205972& and i checked and all the db fields names are spelled correctly to the corresponding field names used in this asp page. I did some more searching and found that when in doubt just delete the drw and start over, but the way we have it there is no DRW component to delete in Normal view of front page. kinda lost as to what to do
|
|
|
|
hhammash
Posts: 1064 Joined: 8/19/2002 Status: offline
|
RE: AND / OR paramaters - 9/19/2002 15:31:17
Hi lulu, In noticed that all your fields but one have a text value. The method I posted for you can work just fine for all text fields. Did you try the link I setup for you? I have a suggestion. Since you are gowin into lot of troubles working this out for an autonumber filed, why don' t you put and ID field with text value instead of the autonumber. Like northwind customer table where you have customer ID as text. If all your search fields are Text, my method above will work. Are you going to search using the autonumber field? Regards Hisham
|
|
|
|
lu lu
Posts: 418 From: wpg, mb Status: offline
|
RE: AND / OR paramaters - 9/19/2002 15:35:09
yes, i' m going to sometimes wanna search using the autonumber field.
|
|
|
|
lu lu
Posts: 418 From: wpg, mb Status: offline
|
RE: AND / OR paramaters - 9/19/2002 17:25:07
rdouglass i looked over you example that set me on this path and i noticed how the submit button was set up, so i implemented the same. But still no luck retrieving a query, what could be wrong? I also tried doing a search using " ID" and " province" and the dreaded error occured again: Too few parameters. Expected 1. <% ' FP_ASP ASP Automatically generated by a Frontpage Component. Do not Edit. On Error Resume Next strErrorUrl = " " If Request.ServerVariables(" REQUEST_METHOD" ) = " POST" Then If Request.Form(" VTI-GROUP" ) = " 0" Then Err.Clear Set fp_conn = Server.CreateObject(" ADODB.Connection" ) FP_DumpError strErrorUrl, " Cannot create connection" Set fp_rs = Server.CreateObject(" ADODB.Recordset" ) FP_DumpError strErrorUrl, " Cannot create record set" fp_conn.Open Application(" applicant_ConnectionString" ) FP_DumpError strErrorUrl, " Cannot open database" fp_rs.Open " Results2" , fp_conn, 1, 3, 2 ' adOpenKeySet, adLockOptimistic, adCmdTable FP_DumpError strErrorUrl, " Cannot open record set" fp_rs.AddNew FP_DumpError strErrorUrl, " Cannot add new record set to the database" Dim arFormFields0(18) Dim arFormDBFields0(18) Dim arFormValues0(18) arFormFields0(0) = " occupation" arFormDBFields0(0) = " occupation" arFormValues0(0) = Request(" occupation" ) arFormFields0(1) = " contact_person" arFormDBFields0(1) = " contact_person" arFormValues0(1) = Request(" contact_person" ) arFormFields0(2) = " address" arFormDBFields0(2) = " address1" arFormValues0(2) = Request(" address" ) arFormFields0(3) = " occupation_value" arFormDBFields0(3) = " occupation_value" arFormValues0(3) = Request(" occupation_value" ) arFormFields0(4) = " postal_code" arFormDBFields0(4) = " postal_code" arFormValues0(4) = Request(" postal_code" ) arFormFields0(5) = " number_of_employees" arFormDBFields0(5) = " number_of_employees" arFormValues0(5) = Request(" number_of_employees" ) arFormFields0(6) = " esi_representative" arFormDBFields0(6) = " esi_representative" arFormValues0(6) = Request(" esi_representative" ) arFormFields0(7) = " service_purchased" arFormDBFields0(7) = " service_purchased" arFormValues0(7) = Request(" service_purchased" ) arFormFields0(8) = " comments" arFormDBFields0(8) = " comments" arFormValues0(8) = Request(" comments" ) arFormFields0(9) = " record_input" arFormDBFields0(9) = " record_input" arFormValues0(9) = Request(" record_input" ) arFormFields0(10) = " fax_number" arFormDBFields0(10) = " fax_number" arFormValues0(10) = Request(" fax_number" ) arFormFields0(11) = " province" arFormDBFields0(11) = " province" arFormValues0(11) = Request(" province" ) arFormFields0(12) = " company_name" arFormDBFields0(12) = " company_name" arFormValues0(12) = Request(" company_name" ) arFormFields0(13) = " phone_number" arFormDBFields0(13) = " phone_number" arFormValues0(13) = Request(" phone_number" ) arFormFields0(14) = " line_of_business" arFormDBFields0(14) = " line_of_business" arFormValues0(14) = Request(" line_of_business" ) arFormFields0(15) = " city" arFormDBFields0(15) = " city" arFormValues0(15) = Request(" city" ) arFormFields0(16) = " occupation_name" arFormDBFields0(16) = " occupation_name" arFormValues0(16) = Request(" occupation_name" ) arFormFields0(17) = " sales_volume" arFormDBFields0(17) = " sales_volume" arFormValues0(17) = Request(" sales_volume" ) FP_SaveFormFields fp_rs, arFormFields0, arFormDBFields0 If Request.ServerVariables(" HTTP_USER_AGENT" ) <> " " Then FP_SaveFieldToDB fp_rs, Request.ServerVariables(" HTTP_USER_AGENT" ), " Browser_type" End If If Request.ServerVariables(" REMOTE_HOST" ) <> " " Then FP_SaveFieldToDB fp_rs, Request.ServerVariables(" REMOTE_HOST" ), " Remote_computer_name" End If FP_SaveFieldToDB fp_rs, Now, " Timestamp" If Request.ServerVariables(" REMOTE_USER" ) <> " " Then FP_SaveFieldToDB fp_rs, Request.ServerVariables(" REMOTE_USER" ), " User_name" End If fp_rs.Update FP_DumpError strErrorUrl, " Cannot update the database" fp_rs.Close fp_conn.Close FP_FormConfirmation " text/html; charset=windows-1252" ,_ " Form Confirmation" ,_ " Thank you for submitting the following information:" ,_ " admin_e.asp" ,_ " Return to the form." End If End If %> <% Dim myQueryString myQueryString = " " If Request(" ID" ) = " " then myQueryString = " " else myQueryString = " (ID = ::ID::)" end if If Request(" company_name" ) > " " then If myQueryString = " " then myQueryString = " (company_name LIKE ' %::company_name::%' )" else myQueryString = myQueryString & " AND (company_name LIKE ' %::company_name::%' )" end if end if If Request(" city" ) > " " then If myQueryString = " " then myQueryString = " (city LIKE ' %::city::%' )" else myQueryString = myQueryString & " AND (city LIKE ' %::city::%' )" end if end if If Request(" province" ) > " " then If myQueryString = " " then myQueryString = " (province LIKE ' %::province::%' )" else myQueryString = myQueryString & " AND (province LIKE ' %::province::%' )" end if end if If Request(" phone_number" ) > " " then If myQueryString = " " then myQueryString = " (phone_number LIKE ' %::phone_number::%' )" else myQueryString = myQueryString & " AND (phone_number LIKE ' %::phone_number::%' )" end if end if If Request(" fax_number" ) > " " then If myQueryString = " " then myQueryString = " (fax_number LIKE ' %::fax_number::%' )" else myQueryString = myQueryString & " AND (fax_number LIKE ' %::fax_number::%' )" end if end if If Request(" line_of_business" ) > " " then If myQueryString = " " then myQueryString = " (line_of_business LIKE ' %::line_of_business::%' )" else myQueryString = myQueryString & " AND (line_of_business LIKE ' %::line_of_business::%' )" end if end if If Request(" number_of_employees" ) > " " then If myQueryString = " " then myQueryString = " (number_of_employees LIKE ' %::number_of_employees::%' )" else myQueryString = myQueryString & " AND (number_of_employees LIKE ' %::number_of_employees::%' )" end if end if If Request(" sales_volume" ) > " " then If myQueryString = " " then myQueryString = " (sales_volume LIKE ' %::sales_volume::%' )" else myQueryString = myQueryString & " AND (sales_volume LIKE ' %::sales_volume::%' )" end if end if If Request(" occupation" ) > " " then If myQueryString = " " then myQueryString = " (occupation LIKE ' %::occupation::%' )" else myQueryString = myQueryString & " AND (occupation LIKE ' %::occupation::%' )" end if end if If Request(" esi_representative" ) > " " then If myQueryString = " " then myQueryString = " (esi_representative LIKE ' %::esi_representative::%' )" else myQueryString = myQueryString & " AND (esi_representative LIKE ' %::esi_representative::%' )" end if end if
< Message edited by lu lu -- 9/19/2002 10:17:31 AM >
|
|
|
|
rdouglass
Posts: 9224 From: Biddeford, ME USA Status: offline
|
RE: AND / OR paramaters - 9/20/2002 9:33:53
Can you put a Response.Write in to find out what myQueryString is? Something like: .... ' If query string is still blank, set a No Record Found value If myQueryString = " " then myQueryString = " (company_name = ' xxxx' )" end if Response.Write(myQueryString) %> Also, response.write in your DRW as in: fp_sQry=" SELECT * FROM Results WHERE (" & myQueryString & " )" Response.Write(fp_sQry) fp_sDefault=" company_name = xxxx" ...and post the response.write results? You don' t need to post the whole page code here. That really surprises me (that it didn' t work) since I took your whole page code and put it on one of my servers. I also created a quick DB to emulate your fields but all fields except ID were text. And I really can' t see any significant difference.... You can see your page at work here with the sample DB i set up. I only have 3 records in the DB, but you can see how it works.....
|
|
|
|
lu lu
Posts: 418 From: wpg, mb Status: offline
|
RE: AND / OR paramaters - 9/20/2002 10:28:35
I tried the response write and all seems to work but when i publish it, it doesn' t ? I checked the publish setting for frontpage and tried other tests and all is fine, I emailed my ISP to see if there were server errors when i tried publishing. Could you email me that file so i could try to publish it to verify my theories with the ISP. I also ran a tracert 5 times to my ISP from dos and things were fine 3 out of 5 times. twice some hops timed out? lulu_zinger@yahoo.com
|
|
|
|
lu lu
Posts: 418 From: wpg, mb Status: offline
|
RE: AND / OR paramaters - 10/1/2002 17:36:20
<bump>
< Message edited by lu lu -- 9/30/2002 6:59:28 PM >
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|