04. januar 2003 - 17:15Der er
54 kommentarer og 1 løsning
Fejl i sql
Hej
Jeg har følgende script, hvor der er noget galt med linien "strSQL", fordi den returnerer ikke noget, selvom der er masser den burdte returnere.
SQL'en: Select distinct datopublish from search where (datopublish between #05-01-2003# and #03-01-2004#) order by datopublish
Kan du finde fejlen?
<% Set myConn=Server.CreateObject("ADODB.Connection") myConn.Open ("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE="+server.Mappath("/db/selvet.mdb")) strSQL = "Select distinct datopublish from search where (datopublish between #" & Date() + 1 & "# and #" & Date() + 364 & "#) order by datopublish"
set rs = myConn.execute(strSQL)
do while not rs.EOF if isDate(rs("datopublish")) then myDates = myDates & rs("datopublish") & ", " End If rs.MoveNext Loop
if not myDates = "" then myDates = left(myDates,len(myDates)-2) end if
Efter den nedenstående kode bliver putputet: 09-08-2003 01-02-2003 selvfølgelig formatet skal rettes
<% Set myConn=Server.CreateObject("ADODB.Connection") myConn.Open ("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE="+server.Mappath("/db/selvet.mdb")) strSQL = "Select * from search where (datopublish between #" & (Date() + 1) & "# and #"& (Date() + 364) & " #) order by datopublish" set rs = myConn.execute(strSQL) do while not rs.EOF if isDate(rs("datopublish")) then myDates = myDates & rs("datopublish") & ", " End If rs.MoveNext Loop if not myDates = "" then myDates = left(myDates,len(myDates)-2) end if response.write("***" & myDates & "***") myDateArr = Split(myDates,",") %>
strSQL = "SELECT DISTINCT datopublish FROM search WHERE date > #" & DatePart(DateAdd("d", 1, Date()), "dd-mm-yyyy") & "# AND date < #" & Datepart(DateAdd("d", 364, Date()), "dd-mm-yyyy") & "# order by datopublish"
what you have to notice though, is that the formatDateTime function uses the computers REGIONAL settings, and this means if the server is using Danish Regional Settings you WILL get the wrong format.
The way dates are displayed on the screen is taken from the PC's regional settings which in this case is the SERVER. This has NOTHING to do with how the date is actually stored in the database. Dates are stored as large numbers and that is why I can use Clng to convert it to a long integer.
But "SELECT DISTINCT datopublish FROM search WHERE datopublish <= #2003-01-05# AND datopublish < #2004-01-05# order by datopublish" does the same as "Kommentar: zeusdk 05/01-2003 11:54:57"
SELECT DISTINCT datopublish FROM search WHERE datopublish <= #01/05-2003# AND datopublish < #01/05-2004# order by datopublish
Does the same as "Kommentar: zeusdk 05/01-2003 11:54:57"
And
strSQL = "SELECT DISTINCT datopublish FROM search WHERE (((CLng([datopublish]))>=CLng(Date()) And (CLng([datopublish])) < CLng(DateAdd("yyyy",1,Date()))))"
Is not working because of the 2 "'s in the string.
>what is 05/01-2003 12:28:40 telling us? >what is 05/01-2003 12:28:40 telling us? They are both doing the same as "Kommentar: zeusdk 05/01-2003 11:54:57".
The problem is that some solutions return all the dates and other solutions return no dates.
Microsoft JET Database Engine (0x80040E14) Missing ), ], or Item in query expression '(((CLng([datopublish]))>=CLng(Date()) And (CLng([datopublish])) < 37991)'.
the problem is we have been focused on getting the date correct that we didnt notice <= (less than or equals) which should be >= (Greater than or equals)
Yes, yes, yes, yes !!! :-) It is working now thanks to you :-)
I have another - proberly a very little problem - and that is that I have a dropdown-box where all the dates, which are NOT in the sql-string are listed. But they are not listed at all - instead all the dates are listed. If you also can fix this problem I will give you 100 points ekstra.
<% Set myConn=Server.CreateObject("ADODB.Connection") myConn.Open ("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE="+server.Mappath("/db/selvet.mdb"))
strSQL = "SELECT DISTINCT datopublish FROM search WHERE datopublish >= #" & Year(date) & "-" & month(date) & "-" & Day(date) & "# AND datopublish < #" & Year(dateadd("yyyy",1,date)) & "-" & month(dateadd("yyyy",1,date)) & "-" & Day(dateadd("yyyy",1,date)) & "# order by datopublish" 'strSQL = "Select distinct datopublish from search where (datopublish between #" & Date() + 1 & "# and #" & Date() + 364 & "#) order by datopublish"
set rs = myConn.execute(strSQL)
do while not rs.EOF if isDate(rs("datopublish")) then myDates = myDates & rs("datopublish") & ", " End If rs.MoveNext Loop
if not myDates = "" then myDates = left(myDates,len(myDates)-2) end if
<% 'Jeg skal have en uge til at reagere på dato = date () + 1 datoSlut = DateAdd("yyyy",1,date) i = 0 do while dato <= datoSlut if CDate(myDateArr(i)) <> CDate(dato) then Response.Write "<option value=""" & dato & """>" & dato & "</option>" else i = i + 1 if i > ubound(myDateArr) then i = ubound(myDateArr) end if dato = dateAdd("d",1,dato) loop %>
>So its all working now? Yes, yes - everything :-)
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.