Jeg arbejder med en søgefunktion til en sql base. Søgeformen indeholder nogle tekst felter nogle afkrydsningsfelter og to dropdownbokse.
Min sql streng der udfører søgningen er opbygget således: \"Select * From Tabel Where Kolonne1 Like \'\" & txtfelt & \"%\' and Kolonne2 Like \'\" & Afkryds1 & \"%\' and Kolonne2 Like \'%\" & Afkryds2 & \"%\' and Kolonne3 Like \'\" & dropdown1 & \"%\' and Kolonne4 Like \'%\" & dropdown2 & \"%\'
Funktionen fungerer fint men jeg forsøger nu at give mulighed for at lave dropdown boksene med mulighed for multiple valg.
Jeg er blevet klar over at jeg skal bruge et array og fylde værdierne fra dropdown boksene heri og derpå splitte dem op, men jeg kan ikke få styr på hvordan jeg skal efterfølgende skal fylde dem ind i min sqlsætning for at få den maskimale preformance.
I dette særtema om aspekter af AI ser vi på skiftet fra sprogmodeller til AI-agenter, og hvordan virksomheder kan navigere i spændet mellem teknologisk hastighed og behovet for menneskelig kontrol.
Function BuildSQLString() As String \'.----------------------------------. \'| Bygger SQL-streng til søgning | \'\'----------------------------------\' Dim strSELECT As String Dim strFROM As String Dim strWHERE As String
If chkCustomerID.Value = True Then txtCustomerID.SetFocus strWHERE = \" AND Sta_customer_id = \" & txtCustomerID.Text End If
If chkCustomerName.Value = True Then txtCustomerName.SetFocus strWHERE = strWHERE & \" AND Sta_customer_name LIKE \'%\" & txtCustomerName.Text & \"%\'\" End If
If chkCustomerAdress.Value = True Then txtCustomerAdress.SetFocus strWHERE = strWHERE & \" AND Sta_customer_address LIKE \'%\" & txtCustomerAdress.Text & \"%\'\" End If
If chkCustomerZipcode.Value = True Then txtCustomerZipcode.SetFocus strWHERE = strWHERE & \" AND Sta_customer_zipcodeid = \" & txtCustomerZipcode.Text End If
If chkCustomerCity.Value = True Then txtCustomerCity.SetFocus strWHERE = strWHERE & \" AND Par_zipcode_townname = \'\" & txtCustomerCity.Text & \"\'\" End If
If chkCustomerPhone.Value = True Then txtCustomerPhone.SetFocus strWHERE = strWHERE & \" AND Sta_customer_phone = \'\" & txtCustomerPhone.Text & \"\'\" End If
If chkCustomerFax.Value = True Then txtCustomerFax.SetFocus strWHERE = strWHERE & \" AND Sta_customer_fax = \'\" & txtCustomerFax.Text & \"\'\" End If
If chkCustomerEmail.Value = True Then txtCustomerEmail.SetFocus strWHERE = strWHERE & \" AND Sta_customer_email = \'\" & txtCustomerEmail.Text & \"\'\" End If
If chkCustomerWWW.Value = True Then txtCustomerWWW.SetFocus strWHERE = strWHERE & \" AND Sta_customer_website = \'\" & txtCustomerWWW.Text & \"\'\" End If
If chk_CustomerGroups.Value = True Then cmb_CustomerGroups.SetFocus strWHERE = strWHERE & \" AND opr_customer_grouping.opr_customer_grouping_group_id_from_opr_customer_groups = \" & cmb_CustomerGroups.Value End If
If chk_PrivatePerson.Value = True Then chk_ChoicePrivatePerson.SetFocus strWHERE = strWHERE & \" AND Sta_customer.sta_customer_privateperson = - 1\" End If
BuildSQLString = \"SELECT \" & strSELECT BuildSQLString = BuildSQLString & \"FROM \" & strFROM If strWHERE <> \"\" Then BuildSQLString = BuildSQLString & \" WHERE \" & Mid$(strWHERE, 6)
I think it would too :o) But do you understand what I mean about setting the strWHERE to \"1\" at the start? This obviosuly isnt necessary as it is working. Its just a suggestion to avoid doing the Mid(..
Exactly! \"WHERE 1\" will return all records. If any search fields were selected then you will get your WHERE 1 and blabla = value and blabla = value. Without having to use mid.
jeg tror jeg forstår princippet i opbygningen af den sql streng dfens, men jeg er ikke i stand til at læse hvordan jeg skal putte værdierne fra en dropdown boks med multiple valg ind i opbygningen
undskyld jeg er lidt lang i spyttet men jeg har haft problemer med at få adgang til experten.
Jeg er bange for at mine array og sql kundskaber ikke rækker til at få implementeret dit løsningsforslag.
Kunne du eventuelt skitsere hvordan du ville omskrive: strWHERE = strWHERE & \" AND Sta_customer_phone = \'\" & txtCustomerPhone.Text & \"\'\" hvis det i stedet for et tekst felt var værdierne fra et array der skulle fyldes ind?
tjah efter min opfattelse taler vi mest sql i og med det handler om at opbygge en sqlsætning. Og sætningen skal afvikles med en sql 7 så vi taler ikke access?
Hi dfens> yes I know we are talking SQL, but there must be some sort of user interface (Access, VB, WEB(asp, vbs, jscript) or something) and it all depends on this on how things are done. Yes the idea is still the same but the coding will more than likely be different. What do you say bispen?
Okay nu er jeg med på hvad du spurgte til tidligere. Jeg troede at selve sql\'en kunne opbygges uafhængigt af applikationen den skal kaldes fra - sorry. Sql kaldet skal afvikles fra en asp side (vb script).
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.