ckangas7
asked on
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax on LONG SQL Statement
Have the below code. I know the SQL statement is good as it runs fine in SQL 2000 query analyzer. When I try to run it via ASP I get the following error:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near 'tblDocumentInfo'.
/reports/NewDTReport.asp, line 80
Line 80 is the one that reads "set rs = conn.execute(strSQL)"
I can see no syntax errors. Any Ideas? I am an ASP newbie.
'Begin ASP Code
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title>New DT Report</title>
<STYLE TYPE="text/css">
<!--
.darkrow, .darkrow TD, .darkrow TH
{
background-color:052651;
color:white;
}
body {
background-color: #990000;
}
.style1 {color: #FFFFFF}
.style3 {font-size: x-large}
a:link {
color: #FFFFFF;
}
a:visited {
color: #FFFFFF;
}
a:hover {
color: #FFFFFF;
}
a:active {
color: #FFFFFF;
}
-->
</STYLE>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head >
<body>
<table width="1054" border="0">
<tr>
<td><span class="style1"><img src="../images/v_logo.gif" width="96" height="70"></span></td>
<td valign="middle"><div align="center"><span class="style1"><span class="style3">NEW DT Report </span></span></div></td>
<td align="right" valign="bottom"><a href="show_all.asp"><img src="butt.gif" width="158" height="35" border="0"></a></td>
<td align="right" valign="bottom"><a href="search.htm"><img src="searchbut.gif" width="125" height="35" border="0" align="bottom"></a></td>
</tr>
<tr>
<td><span class="style1"><a href="Report_input.htm"><i mg src="runagain.gif" width="230" height="35" border="0"></a></span></td >
<td valign="top"> </td>
<td valign="bottom"> </td >
<td valign="bottom"> </td >
</tr>
<tr>
<td width="231"><span class="style1"></span></td >
<td width="513" valign="top"><div align="center"><span class="style1"></span></di v></td>
<td width="161" valign="bottom"> </td >
<td width="131" valign="bottom"><div align="right"></div></td>
</tr>
</table>
<%
'Create Database Connection and Open the Recordset
set conn=Server.CreateObject(" ADODB.Conn ection")
strconn="DSN=reports;UID=r eporman;PW D=reports"
conn.Open strConn
strSQL = "select tblparty.sNameLast as 'Market Source',"&_
"sum( case when sMarketSource = 'AMERICAN TITLE COMPANY' THEN 1 ELSE 0 END) [AMERICAN TITLE]"&_
", sum( case when sMarketSource = 'ATLANTIC ALLIANCE' THEN 1 ELSE 0 END) [ATLANTIC ALLIANCE]"&_
", sum( case when sMarketSource = 'HOLGATE TITLE COMPANY' THEN 1 ELSE 0 END) [HOLGATE TITLE]"&_
", sum( case when sMarketSource = 'CANYON TITLE' THEN 1 ELSE 0 END) [CANYON TITLE]"&_
", sum( case when sMarketSource = 'DENVER TITLE COMPANY' THEN 1 ELSE 0 END) [DENVER TITLE]"&_
", sum(case when SMarketSource in"&_
"('AMERICAN TITLE COMPANY','ATLANTIC ALLIANCE','HOLGATE TITLE COMPANY','CANYON TITLE ',"&_
"'DENVER TITLE COMPANY') then 1 else 0 end) as Totals"&_
"From tblDocumentInfo inner join tblparty on tblDocumentinfo.irecordid = tblparty.irecordid"&_
"Where( tblDocumentInfo.sMarketSou rce = 'American Title Company'"&_
"or tblDocumentInfo.sMarketSou rce = 'Atlantic Alliance'"&_
"or tblDocumentInfo.sMarketSou rce = 'Holgate Title Company'"&_
"or tblDocumentInfo.sMarketSou rce = 'Canyon Title '"&_
"or tblDocumentInfo.sMarketSou rce = 'Denver Title Company' )"&_
"and tblDocumentInfo.sInstrumen tType in ('DEED OF TRUST','MORTGAGE')"&_
"and tblDocumentInfo.dtFiledDat e >= convert(datetime, '2007-02-01' , 120)"&_
"and tblDocumentInfo.dtFiledDat e < convert(datetime, '2007-03-01', 120)"&_
"and tblparty.tiPartyType = '2'"&_
"group by tblparty.sNameLast"
set rs = conn.execute(strSQL)
%>
<TABLE width="21%" border=3 cellpadding=3 cellspacing=0 bgcolor="#FFFFFF">
<tr CLASS="darkrow">
<td><div align="left"><strong>Marke t Source</strong></div></td>
<td><strong>AMERICAN TITLE</strong></td>
<td><strong>ATLANTIC ALLIANCE</strong></td>
<td><strong>HOLGATE TITLE</strong></td>
<td><strong>CANYON TITLE</strong></td>
<td><strong>DENVER TITLE</strong></td>
<td><strong>TOTAL</strong> </td>
</tr>
<%
if (rs.eof) then
%>
<tr>
<td>
No records found for Report
</td>
</tr>
<%
'Loop through the recordset and display address information - Note the hyperlink in the name field to go to the Address_Book_Edit.asp page.
else
Do while not rs.eof
%>
<tr>
<td width="8%"><%=rs("Market Source")%> </td>
<td width="10%"><%=rs("AMERICA N TITLE")%> </td>
<td width="10%"><%=rs("ATLANTI C ALLIANCE")%> </td>
<td width="10%"><%=rs("HOLGATE TITLE")%> </td>
<td width="10%"><%=rs("CANYON TITLE")%> </td>
<td width="10%"><%=rs("DENVER TITLE")%> </td>
<td width="10%"><%=rs("Totals" )%> </ td>
</tr>
<%
rs.movenext
loop
end if
%>
</tr>
</table>
</body>
</html>
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near 'tblDocumentInfo'.
/reports/NewDTReport.asp, line 80
Line 80 is the one that reads "set rs = conn.execute(strSQL)"
I can see no syntax errors. Any Ideas? I am an ASP newbie.
'Begin ASP Code
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title>New DT Report</title>
<STYLE TYPE="text/css">
<!--
.darkrow, .darkrow TD, .darkrow TH
{
background-color:052651;
color:white;
}
body {
background-color: #990000;
}
.style1 {color: #FFFFFF}
.style3 {font-size: x-large}
a:link {
color: #FFFFFF;
}
a:visited {
color: #FFFFFF;
}
a:hover {
color: #FFFFFF;
}
a:active {
color: #FFFFFF;
}
-->
</STYLE>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head
<body>
<table width="1054" border="0">
<tr>
<td><span class="style1"><img src="../images/v_logo.gif"
<td valign="middle"><div align="center"><span class="style1"><span class="style3">NEW DT Report </span></span></div></td>
<td align="right" valign="bottom"><a href="show_all.asp"><img src="butt.gif" width="158" height="35" border="0"></a></td>
<td align="right" valign="bottom"><a href="search.htm"><img src="searchbut.gif" width="125" height="35" border="0" align="bottom"></a></td>
</tr>
<tr>
<td><span class="style1"><a href="Report_input.htm"><i
<td valign="top"> </td>
<td valign="bottom"> </td
<td valign="bottom"> </td
</tr>
<tr>
<td width="231"><span class="style1"></span></td
<td width="513" valign="top"><div align="center"><span class="style1"></span></di
<td width="161" valign="bottom"> </td
<td width="131" valign="bottom"><div align="right"></div></td>
</tr>
</table>
<%
'Create Database Connection and Open the Recordset
set conn=Server.CreateObject("
strconn="DSN=reports;UID=r
conn.Open strConn
strSQL = "select tblparty.sNameLast as 'Market Source',"&_
"sum( case when sMarketSource = 'AMERICAN TITLE COMPANY' THEN 1 ELSE 0 END) [AMERICAN TITLE]"&_
", sum( case when sMarketSource = 'ATLANTIC ALLIANCE' THEN 1 ELSE 0 END) [ATLANTIC ALLIANCE]"&_
", sum( case when sMarketSource = 'HOLGATE TITLE COMPANY' THEN 1 ELSE 0 END) [HOLGATE TITLE]"&_
", sum( case when sMarketSource = 'CANYON TITLE' THEN 1 ELSE 0 END) [CANYON TITLE]"&_
", sum( case when sMarketSource = 'DENVER TITLE COMPANY' THEN 1 ELSE 0 END) [DENVER TITLE]"&_
", sum(case when SMarketSource in"&_
"('AMERICAN TITLE COMPANY','ATLANTIC ALLIANCE','HOLGATE TITLE COMPANY','CANYON TITLE ',"&_
"'DENVER TITLE COMPANY') then 1 else 0 end) as Totals"&_
"From tblDocumentInfo inner join tblparty on tblDocumentinfo.irecordid = tblparty.irecordid"&_
"Where( tblDocumentInfo.sMarketSou
"or tblDocumentInfo.sMarketSou
"or tblDocumentInfo.sMarketSou
"or tblDocumentInfo.sMarketSou
"or tblDocumentInfo.sMarketSou
"and tblDocumentInfo.sInstrumen
"and tblDocumentInfo.dtFiledDat
"and tblDocumentInfo.dtFiledDat
"and tblparty.tiPartyType = '2'"&_
"group by tblparty.sNameLast"
set rs = conn.execute(strSQL)
%>
<TABLE width="21%" border=3 cellpadding=3 cellspacing=0 bgcolor="#FFFFFF">
<tr CLASS="darkrow">
<td><div align="left"><strong>Marke
<td><strong>AMERICAN TITLE</strong></td>
<td><strong>ATLANTIC ALLIANCE</strong></td>
<td><strong>HOLGATE TITLE</strong></td>
<td><strong>CANYON TITLE</strong></td>
<td><strong>DENVER TITLE</strong></td>
<td><strong>TOTAL</strong>
</tr>
<%
if (rs.eof) then
%>
<tr>
<td>
No records found for Report
</td>
</tr>
<%
'Loop through the recordset and display address information - Note the hyperlink in the name field to go to the Address_Book_Edit.asp page.
else
Do while not rs.eof
%>
<tr>
<td width="8%"><%=rs("Market Source")%> </td>
<td width="10%"><%=rs("AMERICA
<td width="10%"><%=rs("ATLANTI
<td width="10%"><%=rs("HOLGATE
<td width="10%"><%=rs("CANYON TITLE")%> </td>
<td width="10%"><%=rs("DENVER TITLE")%> </td>
<td width="10%"><%=rs("Totals"
</tr>
<%
rs.movenext
loop
end if
%>
</tr>
</table>
</body>
</html>
The error thrown on that line is telling you your SQL statement is wrong.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You need to output the result of strSQL before the line:
set rs = conn.execute(strSQL)
If you cannot tell what is the error from the output, post the result here.
set rs = conn.execute(strSQL)
If you cannot tell what is the error from the output, post the result here.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK, can you please tell me how I can output the result of strSQL before the line:
set rs = conn.execute(strSQL)?
set rs = conn.execute(strSQL)?
response.write strSQL
on error resume next
set rs = conn.execute(strSQL)
if err then
response.write err.number & " " & err.description & " " & err.source & "<br>" & strSQL
end if
on error resume next
set rs = conn.execute(strSQL)
if err then
response.write err.number & " " & err.description & " " & err.source & "<br>" & strSQL
end if
ASKER
All right that did it. You were correct it was the way I parsed the SQL statement. A few spaces here and there fixed the problem. Awesome, I'm halfway home.
You are welcome.
LOL