Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax query error

Status
Not open for further replies.

cfsponge

Programmer
Feb 22, 2006
44
US
What am I doing incorrectly with this statement? The SQL runs perfectly in SQL Server.

Dim rsRedBoxes
Set rsRedBoxes = Server.CreateObject("ADODB.Recordset")
sSQL = "SELECT frontBlurb, frontBlurbAlt FROM tblTemplates WHERE frontBlurb IS NOT NULL"

rsRedBoxes.Open sSQL, strConn, adOpenStatic, adLockReadOnly, adCmdTable

rsRedBoxes.Filter = "templateName = 'apartment.asp'"

========================
Microsoft OLE DB Provider for SQL Server error '80040e14'
Incorrect syntax near the keyword 'SELECT'.
/madison/site/_includes/redboxes.inc.asp, line 5
 
I'm doing this query from an ASP book that I'm reading. It had that 4th attribute there. If I remove adCmdTable, I get this error:

ADODB.Recordset error '800a0cc1'
Item cannot be found in the collection corresponding to the requested name or ordinal.
/madison/site/_includes/redboxes.inc.asp, line 6 (which is the line that has the .Filter command)
 
Use adCmdTable if you want the entire table... so use it if you just want to do [tt]SELECT * FROM tblTemplates[/tt]

use adCmdText for the SQL statement given above.

The reason you get the error on setting the .Filter property is... how can I filter on a field I do not have!

Probably you want to ditch the filter and just put the conditional statentment in your WHERE clause like this:[tt]

sSQL = "SELECT frontBlurb, frontBlurbAlt " _
& "FROM tblTemplates " _
& "WHERE frontBlurb IS NOT NULL " _
& "[red]AND templateName = 'apartment.asp'[/red]"

rsRedBoxes.Open sSQL, strConn, adOpenStatic, adLockReadOnly, [red]adCmdText[/red]
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top