HI I'm trying to use dynamic stored procedures. My where clause is built up in the asp code, i have a stored procedure which calls that where clause and should display the info back to the screen, except i get an error
Incorrect syntax near 'Col004'
here is my stored procedure
here is the asp page where the where clause gets built up, called LPRSearchResults.asp
here is the main asp page that calls the other asp page plus stored procedure
thanks
rich
Incorrect syntax near 'Col004'
here is my stored procedure
Code:
CREATE PROCEDURE spTest (@strWhere varchar(255))
AS
DECLARE @SQLStatement varchar(255)
SELECT @SQLStatement = "SELECT Col003, Col004, Col005, Col006, Col007, Col008, Col011 FROM LPRLICASE WHERE "
+ @strWhere
EXEC(@SQLStatement)
GO
here is the asp page where the where clause gets built up, called LPRSearchResults.asp
Code:
SchTradingName = Trim(replace(request("SchTradingName"),"'","''"))
SchStreetName = Trim(replace(request("SchStreetName"),"'","''"))
txtLicType = Trim(replace(request("txtLicType"),"'","''"))
'Build strWhere string (clear first):
strWhere = ""
If SchTradingName <> "" Then
strWhere = strWhere & "Col004 LIKE '%" & SchTradingName & "%'"
else
strWhere = strWhere & "(Col004 LIKE '%%' or Col004 is null)"
End If
If SchStreetName <> "" Then
If strWhere <> "" Then
strWhere = strWhere & " AND "
End If
strWhere = strWhere & "Col005 LIKE '%" & SchStreetName & "%'"
else
If strWhere <> "" Then
strWhere = strWhere & " AND "
End If
strWhere = strWhere & "(Col005 LIKE '%%' or Col005 is null)"
End If
If txtLicType <> "" and txtLicType <> "-- All Licence Types --" Then
If strWhere <> "" Then
strWhere = strWhere & " AND "
End If
strWhere = strWhere & "Col003 LIKE '%" & txtLicType & "%'"
else
If strWhere <> "" Then
strWhere = strWhere & " AND "
End If
strWhere = strWhere & "(Col003 LIKE '%%' or Col003 is null)"
End If
here is the main asp page that calls the other asp page plus stored procedure
Code:
%>
<!--#INCLUDE VIRTUAL="/training48/includes/LPR/LPRSearchResults.asp"-->
<%
'set my connections etc then call the sp as below
objCon.Execute "spTest " & strWhere
thanks
rich