Felmeddelande: Gissar att StartDate eller EndDate inte innehåller det du förväntar dej, testa att skriva ut SQL-satsen så brukar man fort se vad som är fel. Jag kan inte se något fel, har tittat i databasen (MSSQL) så att tidsformaten stämmer. Ahh, det är SQL Server, då ska det vara ' istället för # runt datumen. Hej Johan, jag tackar för hjälpen, underbart! Säkerligen felaktiga indata, koll vad StartDate och starttid innehåller samt vad DateDiff("d", StartDate, starttid, 2, 2) ger för resultat.Incorrect syntax near '00'.
Microsoft OLE DB Provider for SQL Server (0x80040E14)
Line 1: Incorrect syntax near '00'.
/demobilar/cal_week.asp, line 105
Jag ser inte vad problemet är, har stirrat mig blind och behöver er hjälp.
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Connections/Demobokning.asp" -->
<% Response.Expires = 0
CurrentDate = Trim(Request("datum"))
If CurrentDate = "" Then
CurrentDate = date()
End If
Session("viewtype") = "week"
StartDate = DateAdd("d", -(CInt(weekday(CurrentDate, 2)) - 1), CurrentDate)
EndDate = DateAdd("d", 6, StartDate)
WeekNr = DatePart("ww", StartDate, 2, 2)
'FIXA KONSTANTER
intNameWidth = 250 'Namn-kolumnens bredd
intDayWidth = 48 'Dag-kolumnens bredd
intRowHeight = 20 'Radhöjden i hela tabellen
intTableLeftOffset = intNameWidth + 2
intTableTopOffset = 22
'HÄMTA DATA FRÅN DATABASEN
'Set Conn = Server.CreateObject("ADODB.Connection")
'Set rsCars = Server.CreateObject("ADODB.Recordset")
'Conn.Open "demobilar"
'sql = "SELECT bilid, namn, regnr FROM bilar WHERE status = 1 ORDER BY namn, regnr"
'rsCars.Open sql, Conn, 1, 4
%>
<%
Dim rsCars
Dim rsCars_numRows
Set rsCars = Server.CreateObject("ADODB.Recordset")
rsCars.ActiveConnection = MM_Demobokning_STRING
rsCars.Source = "SELECT bilid, namn, regnr FROM Tb_demobilar WHERE status = 1 ORDER BY namn, regnr"
rsCars.CursorType = 0
rsCars.CursorLocation = 2
rsCars.LockType = 1
rsCars.Open()
rsCars_numRows = 0
%>
<html>
<head>
<title>Kalender - Vecka</title>
<link REL="stylesheet" HREF="style/overlib.css" TYPE="text/css">
<link REL="stylesheet" TYPE="text/css" HREF="style/ie4.css">
<script LANGUAGE="JavaScript"><!--
function OpenForm(carId, datum, startHour, bokningsId) {
if (carId != '' && bokningsId == ''){
window.self.location = 'form.asp?action=ny&datum=' + datum + '&h=' + startHour + '&id=' + carId;
} else if(carId != '' && bokningsId != ''){
window.self.location = 'form.asp?action=visa&bokningsId=' + bokningsId + '&id=' + carId;
}
}
//--></script>
</head>
<body topmargin="10" leftmargin="5" bgcolor="#ffffff">
<div ID="overDiv" STYLE="position:absolute; visibility:hide; z-index: 5;"></div>
<script LANGUAGE="JavaScript" SRC="style/overlib.js"></script>
<div id="Links" style="position: absolute; top: 10; left: 10; z-index: 1; height: 15; width: 524">
<table border="0" width="100%" cellspacing="0" cellpadding="0" height="100%">
<tr>
<td width="30%" valign="top" align="left" height="100%">
<font face="Verdana,Geneva,Arial,Helvetica,sans-serif" size="1">
</font></td>
<td width="40%" valign="top" align="center" height="100%">
<font face="Verdana,Geneva,Arial,Helvetica,sans-serif" size="1">
<b>Vecka: <%=WeekNr %></b></font></td>
<td width="30%" valign="top" align="right" height="100%">
<font face="Verdana,Geneva,Arial,Helvetica,sans-serif" size="1">
</font></td>
</tr>
</table>
</div>
<div id="Links" style="position: absolute; top: 27; left: 10; z-index: 1;">
<% antal = -1
WeekLenght = (intDayWidth * 7) + 6
Do While Not rsCars.EOF
antal = antal + 1
Dim rs
Dim rs_numRows
Set rs = Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = MM_Demobokning_STRING
rs.Source = "SELECT * FROM Tb_demobokningar WHERE " & _
"((starttid BETWEEN #" & StartDate & " 00:00:00# AND #" & _
EndDate & " 23:59:59#) OR (sluttid > #" & StartDate & " 00:00:00# AND " & _
"starttid < #" & EndDate & " 00:00:00#)) AND " & _
"(bilId = " & rsCars(0) & ")"
rs.CursorType = 0
rs.CursorLocation = 2
rs.LockType = 1
rs.Open() 'OBS Här skall felet sitta
rs_numRows = 0
Do While Not rs.EOF
'HÄMTA STARTVÄRDEN FÖR DENNA BOKNING
id = Trim(rs(0))
starttid = Trim(rs(1))
sluttid = Trim(rs(2))
bilid = Trim(rs(3))
biltyp = Trim(rs(6))
firstname = Trim(rs(7))
lastname = Trim(rs(8))
customer = Trim(rs(9))
kundregnr = Trim(rs(11))
mottagentid = Trim(rs(15))
ThisStartTime = starttid
ThisEndTime = sluttid
'KOLLA OM STARTTIDEN ÄR I DENNA VECKAN
If CInt(DateDiff("d", StartDate, starttid, 2, 2)) < 0 Or _
CInt(DateDiff("d", StartDate, starttid, 2, 2)) > 7 Then
ThisStartTime = StartDate & " 00:00:00"
End If
'TA FRAM VÄRDEN TILL LAGRET FÖR BOKNINGEN
intDivTop = 22 + (antal * intRowHeight) + antal
intDivLeft = intNameWidth + _
(CInt(DateDiff("h", StartDate, ThisStartTime, 2, 2)) * 2) + _
CInt(DateDiff("d", StartDate, ThisStartTime, 2, 2)) + 2
intDivWidth = (CInt(DateDiff("h", ThisStartTime, ThisEndTime, 2, 2)) * 2) + _
CInt(DateDiff("d", ThisStartTime, ThisEndTime, 2, 2))
intDivHeight = intRowHeight
'KOLLA OM SLUTTIDEN ÄR I DENNA VECKAN
If CInt(DateDiff("d", sluttid, EndDate, 2, 2)) < 0 Then
intDivWidth = (WeekLenght + intTableLeftOffset) - intDivLeft
End If
'TA FRAM VAD SOM SKA VISAS I BOKNINGEN
intDivId = id
TempStarttid = starttid
GetDate TempStarttid
TempSluttid = sluttid
GetDate TempSluttid
If starttid <> mottagentid Then
bColor = "#00CC66"
Else
bColor = "#C0C0C0"
End If
strRubrik = customer
strtext = "<b>Bil:</b><br>" & UCase(kundregnr) & "<br><br>" & _
"<b>Bokare:</b><br>" & firstname & " " & lastname & "<br><br>" & _
"<b>Datum:</b><br>" & Mid(CStr(TempStarttid), 1, 16) & " -<br>" & _
Mid(CStr(TempSluttid), 1, 16)
%>
<div id="<%= intDivId %>" style="position: absolute; top: <%= intDivTop %>; left: <%= intDivLeft %>; z-index: 2; height: <%= intDivHeight %>; width: <%= intDivWidth %>"
onMouseOver="drc('<%= strText %>','<%= strRubrik %>'); return true;" onMouseOut="nd(); return true;"
onclick="OpenForm(<%= bilid %>, '', '','<%= id %>')">
<table border="0" width="100%" cellspacing="0" cellpadding="0" bgcolor="<%= bColor %>" height="100%">
<tr>
<td width="100%" valign="middle" align="center" height="100%">
<font face="Verdana,Geneva,Arial,Helvetica,sans-serif" size="1"><%= strBooking %></font></td>
</tr>
</table>
</div>
<% rs.MoveNext
Loop
Set rs = Nothing
rsCars.MoveNext
Loop
rsCars.MoveFirst %>
<% WriteTable intNameWidth, intDayWidth, intRowHeight, antal %>
</div>
</body>
</html>
<%
sql.Close()
Set sql = Nothing
%>
<% rsCars.Close
Connect.Close %>
<%
Sub GetDate(datum)
yy = Year(datum)
mm = Month(datum)
If mm < 10 Then mm = "0" & mm
dd = Day(datum)
If dd < 10 Then dd = "0" & dd
h = Hour(datum)
If h < 10 Then h = "0" & h
m = Minute(datum)
If m < 10 Then m = "0" & m
datum = yy & "-" & mm & "-" & dd & " " & h & ":" & m & ":01"
End Sub
%>
<% Sub WriteTable(intNameWidth, intDayWidth, intRowHeight, antal)
If antal = "" Then
antal = 1
End If
%>
<table border="0" cellspacing="1" cellpadding="0" bgcolor="#333333">
<tr>
<td width="<%= intNameWidth %>" height="<%= intRowHeight %>" valign="middle" align="left" bgcolor="#2A547F"> </td>
<% Dim aDay(6, 1)
'FIXA "KONSTANTER"
aDay(0,0) = "Mån"
aDay(1,0) = "Tis"
aDay(2,0) = "Ons"
aDay(3,0) = "Tor"
aDay(4,0) = "Fre"
aDay(5,0) = "Lör"
aDay(6,0) = "Sön"
For i = 0 To 6
aDay(i, 1) = DateAdd("d", i, StartDate) %>
<td width="<%= intDayWidth %>" height="<%= intRowHeight %>" valign="middle" align="center" bgcolor="#2A547F">
<font face="Verdana,Geneva,Arial,Helvetica,sans-serif" size="1" color="#FFFFFF">
<b><%= aDay(i, 0) %></b> <%= Day(DateAdd("d", i, StartDate)) %></font></td>
<% Next %>
</tr>
<% Do While Not rsCars.EOF %>
<tr>
<td width="<%= intNameWidth %>" height="<%= intRowHeight %>" valign="middle" align="left" bgcolor="#FFFFFF">
<font face="Verdana,Geneva,Arial,Helvetica,sans-serif" size="1">
<a CLASS="calBlack" href="cal_days.asp?datum=<%= CurrentDate %>&id=<%= rsCars(0) %>"><%= rsCars(1) & " - " & rsCars(2) %></a></font></td>
<% For i = 0 To 6 %>
<td width="<%= intDayWidth %>" height="<%= intRowHeight %>" valign="middle" align="left" bgcolor="#FFFFFF">
<font face="Verdana,Geneva,Arial,Helvetica,sans-serif" size="1"> </font>
<% Next %>
</tr>
<% rsCars.MoveNext
Loop %>
</table>
<% End Sub %>Sv: Incorrect syntax near '00'.
/JohanSv:Incorrect syntax near '00'.
Tidsformatet är ex: 2005-10-10 08:00:00 vilket jag anser stämmer in.
Set rs = Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = MM_Demobokning_STRING
rs.Source = "SELECT * FROM dbo.Tb_demobokningar WHERE " & _
"((starttid BETWEEN #" & StartDate & " 00:00:00# AND #" & _
EndDate & " 23:59:59#) OR (sluttid > #" & StartDate & " 00:00:00# AND " & _
"starttid < #" & EndDate & " 00:00:00#)) AND " & _
"(bilId = " & rsCars(0) & ")"
* line 98 rs.Open()
Do While Not rs.EOF
Felkod:
Microsoft OLE DB Provider for SQL Server (0x80040E14)
Line 1: Incorrect syntax near '00'.
/demobilar/cal_week.asp, line 98 *Sv: Incorrect syntax near '00'.
/JohanSv:Incorrect syntax near '00'.
Kanske du kan hjälpa mig med detta också:
If CInt(DateDiff("d", StartDate, starttid, 2, 2)) < 0 Or _
CInt(DateDiff("d", StartDate, starttid, 2, 2)) > 7 Then
ThisStartTime = StartDate & " 00:00:00"
End If
Feltyp:
Körningsfel i Microsoft VBScript (0x800A0006)
Spill: 'CInt'
/demobilar/cal_week.asp, line 101Sv: Incorrect syntax near '00'.
/Johan