SELECT kalla,forfattare,rubrik,text,datum,kategori,nID from nyheter WHERE (kalla LIKE '%lorem%') OR (forfattare LIKE '%lorem%') OR (rubrik LIKE '%lorem%') OR (text LIKE '%lorem%') OR (datum LIKE '%lorem%') ORDER BY datum;
How do you count the number of records that above sqlstatement produces?
SELECT COUNT(nID) As Antal, kalla,forfattare,rubrik,text,datum,kategori,nID from nyheter WHERE (kalla LIKE '%lorem%') OR (forfattare LIKE '%lorem%') OR (rubrik LIKE '%lorem%') OR (text LIKE '%lorem%') OR (datum LIKE '%lorem%') ORDER BY datum;
SELECT COUNT(nID) kalla,forfattare,rubrik,text,datum,kategori,nID from nyheter WHERE (kalla LIKE '%lorem%') OR (forfattare LIKE '%lorem%') OR (rubrik LIKE '%lorem%') OR (text LIKE '%lorem%') OR (datum LIKE '%lorem%') ORDER BY datum;
Ellers prøv: SELECT COUNT(*) kalla,forfattare,rubrik,text,datum,kategori,nID from nyheter WHERE (kalla LIKE '%lorem%') OR (forfattare LIKE '%lorem%') OR (rubrik LIKE '%lorem%') OR (text LIKE '%lorem%') OR (datum LIKE '%lorem%') ORDER BY datum;
SELECT COUNT(*) kalla,forfattare,rubrik,text,datum,kategori from nyheter WHERE... resultatet: Error Type: Microsoft JET Database Engine (0x80040E14) Syntaxfel (operator saknas) i frågeuttrycket 'COUNT(*) kalla'. /axelsons/searchnyheter.asp, line 202
line202: <%Set rs = db.Execute(strSQL)%> som hör till: <% Set db = Server.CreateObject("ADODB.Connection") db.Open "Provider=Microsoft.Jet.OLEDB.4.0;" _ &"Data Source=C:\documents and settings\benke\skrivbord\webarbeten\axelsons\db\axelsons.mdb;" %>
SELECT COUNT(*), kalla,forfattare,rubrik,text,datum,kategori,nID from nyheter WHERE (kalla LIKE '%lorem%') OR (forfattare LIKE '%lorem%') OR (rubrik LIKE '%lorem%') OR (text LIKE '%lorem%') OR (datum LIKE '%lorem%') ORDER BY datum;
Men det skal nok højst sandsynlig være sådan her eftersom du oxo har et reseveret ord i din SQL (Text)
SELECT COUNT(*), kalla,forfattare,rubrik,[text],datum,kategori,nID from nyheter WHERE (kalla LIKE '%lorem%') OR (forfattare LIKE '%lorem%') OR (rubrik LIKE '%lorem%') OR (text LIKE '%lorem%') OR (datum LIKE '%lorem%') ORDER BY datum;
Error Type: Microsoft JET Database Engine (0x80040E21) Du försökte köra en fråga med en mängdfunktion som inte innehöll det angivna uttrycket 'kalla'. /axelsons/searchnyheter.asp, line 202
'get the sql string strSQL = SQLSearchWordsTableAndJoin(strTemp, arrFieldsToSearch, "datum", strSearchCriteria, False, NULL) 'strSQL = SQLSearchWordsTableAndJoin(str ' Temp, arrFieldsToSearch, "tblCD.title", ' strSearchCriteria, False, "tblCD.display ' = true") ' ###################################### ' ######################################## ' ###################################### ' # ' # Procedure:SQLSearchWordsTableAndJoin ' (strTableName, arrFieldsToSearch, strOrd ' erByField, strSearchCriteria, bSearchMus ' tMatchAllWords, strExtraCrit) ' # Purpose: Search database for keywo ' rds on text fields. ' # Date: 29-11-2000 ' # inputs: strTableAndJoin - as strin ' g. table and join string ' # arrFieldsToSearch - as array. ' The field names to search on. ' # strOrderByField - as string. T ' he field to order the query on. ' # strSearchCriteria - as string. ' The form value - search criteria. ' # bSearchMustMatchAllWords - as bo ' olean. Search must match all words or no ' t. ' # strExtraCrit - as string. Ext ' ra criteria that the user has specified ' # outputs: sql string. ' # This code is modified from a 4gu ' ysfromrolla function ' # ' ###################################### ' ######################################## ' ###################################### function SQLSearchWordsTableAndJoin(strTableAndJoin, arrFieldsToSearch, strOrderByField, strSearchCriteria, bSearchMustMatchAllWords, strExtraCrit) Dim strSQL 'as string. Dim arrWords() 'as array. Holds all of the words Dim intWordCounter 'as integer. Counts the number of words To search on. Dim I 'as integer. Standard looping variable Dim intCurrentWord 'as integer. The current word. Dim strTemp 'as string. A temp variable that is used To build the sql string. Dim intArrayCounter 'as integer. Standard looping variable Dim intElementsInArray 'as integer. Gets the number of elements in the array. Fields To search on.
'get the number of elements In the array intElementsInArray = CInt(UBound(arrFieldsToSearch) - 1)
'count spaces because Each space would mean a new word For I = 1 To Len(strSearchCriteria) if mid(strSearchCriteria, I, 1) = " " Then intWordCounter = intWordCounter + 1 Next ' Now, We Add One To Include The First Word intWordCounter = intWordCounter + 1 ReDim arrWords(intWordCounter)
' Now, We Fill The Array With The Words intCurrentWord = 1 For I = 1 To len(strSearchCriteria) if mid(strSearchCriteria, i, 1) = " " Then intCurrentWord = intCurrentWord + 1 Else arrWords(intCurrentWord) = arrWords(intCurrentWord) + mid(strSearchCriteria, I, 1) End if Next ' Now Lets Build The SQL Statement Based On What Search Type bSearchMustMatchAllWords ' First Part Of SQL strSQL = strTableAndJoin & " " 'loop through array To Get all of the fields For intArrayCounter = 0 To CInt(intElementsInArray)
' For Loop To Concatenate SQL String Together For I = 1 To intWordCounter if CBool(bSearchMustMatchAllWords) Then if CInt(I) = 1 Then strTemp = strTemp & "(" 'only put ( first time into Loop if I <> intWordCounter Then strTemp = strTemp & arrFieldsToSearch(intArrayCounter) & " LIKE '%" & arrWords(I) & "%' AND " ElseIf I = intWordCounter Then strTemp = strTemp & arrFieldsToSearch(intArrayCounter) & " LIKE '%" & arrWords(I) & "%'" End if if (strExtraCrit <> "" And CInt(i) = CInt(intWordCounter)) Then strTemp = strTemp & " " & strExtraCrit & " "
if CInt(i) = intWordCounter Then strTemp = strTemp & ")"'only put ) last time into Loop Else if I <> intWordCounter Then strTemp = strTemp & "(" & arrFieldsToSearch(intArrayCounter) & " LIKE '%" & arrWords(I) & "%'" if strExtraCrit <> "" Then strTemp = strTemp & " " & strExtraCrit & " " strTemp = strTemp & ") OR " ElseIf I = intWordCounter Then strTemp = strTemp & "(" & arrFieldsToSearch(intArrayCounter) & " LIKE '%" & arrWords(I) & "%'" if strExtraCrit <> "" Then strTemp = strTemp & " " & strExtraCrit & " " strTemp = strTemp & ")" End if End if Next 'I if CInt(intArrayCounter) < CInt(intElementsInArray) Then strTemp = strTemp & " OR " Next 'intArrayCounter
'If user specified a order by field add this code To the End of the sql string. if Len(strOrderByField) > 0 Or strOrderByField <> "" Then strSQL = strSQL & strTemp & " ORDER BY " & strOrderByField & ";" SQLSearchWordsTableAndJoin = strSQL End function 'response.write strSQL %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html> <head>
<% Set db = Server.CreateObject("ADODB.Connection") db.Open "Provider=Microsoft.Jet.OLEDB.4.0;" _ &"Data Source=C:\documents and settings\benke\skrivbord\webarbeten\axelsons\db\axelsons.mdb;" 'db.Open "Provider=Microsoft.Jet.OLEDB.4.0;" _ '&"Data Source=d:\web\kunder\axelsons\nyhetsdemo\db\axelsons.mdb;" Function CutString (str, intCut) if len(str) > intCut then posstart = InStrRev(str, " ", intCut) if (posstart <> 0) then CutString = Left(str, posstart) & "...<br><a href=""visanyhet.asp?nID="&rs("nID")&""" class=""lasmer"" target=""sida"">Läs hela artikeln >></a>" Exit Function end if end if CutString = str End function %>
<script type="text/javascript" language="JavaScript"> // Define the location of count.asp // Using a path, you may use this code in any subfolder var file='/statistik/count.asp';
var d=new Date(); var s=d.getSeconds(); var m=d.getMinutes(); var x=s*m; f='' + escape(document.referrer); if (navigator.appName=='Netscape'){b='NS';} if (navigator.appName=='Microsoft Internet Explorer'){b='MSIE';} if (navigator.appVersion.indexOf('MSIE 3')>0) {b='MSIE';} u='' + escape(document.URL); w=screen.width; h=screen.height; v=navigator.appName; fs = window.screen.fontSmoothingEnabled; if (v != 'Netscape') {c=screen.colorDepth;} else {c=screen.pixelDepth;} j=navigator.javaEnabled(); info='w=' + w + '&h=' + h + '&c=' + c + '&r=' + f + '&u='+ u + '&fs=' + fs + '&b=' + b + '&x=' + x; document.write('<img src="' + file + '?'+info+ '" width=1 height=1 border=0>');
Error Type: Microsoft JET Database Engine (0x80040E21) You tried to execute a query that does not include the specified expression 'status' as part of an aggregate function. /axelsons/searchnyheter.asp, line 202
Error Type: Microsoft OLE DB Provider for ODBC Drivers (0x80040E14) [Microsoft][Drivrutin för ODBC Microsoft Access] Det går inte att gruppera fält tillagda med '*' (Nyheter). /axelsons/searchnyheter.asp, line 108
Error Type: Microsoft JET Database Engine (0x80040E21) You tried to execute a query that does not include the specified expression 'datum' as part of an aggregate function. /axelsons/searchnyheter.asp, line 169
Error Type: Microsoft JET Database Engine (0x80040E21) Can't group field added with '*'. /axelsons/searchnyheter.asp, line 169
Synes godt om
Ny brugerNybegynder
Din løsning...
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.