Print Page | Close Window

StrSQL + and.

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Database Discussion
Forum Description: Discussion and chat on database related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=11270
Printed Date: 30 March 2026 at 4:19am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: StrSQL + and.
Posted By: Badaboem
Subject: StrSQL + and.
Date Posted: 23 July 2004 at 9:34am
I'm having an issue getting "and" to work properly in this bit of code. I believe i've written it down correctly and have tried several methods, but I keep getting an error.


Set rsDownload = Server.CreateObject("ADODB.RecordSet")
    strSQL = "SELECT Download_ID, Download_Preview, Download_Preview_Movie, Download_Version, D_FreeCommercial, Download_Name, D_Short, D_Added, Download_Hits, Download_SubCat, DComments "  
    strSQL = strSQL & " FROM " & strDbTable & "Downloads WHERE " & strDbTable & "Downloads.Download_SubCat = " & scid & "AND" & strDbTable & "Downloads.D_Short & AND"
   
        'If the user has selected all or any words then build the where clause with the words to be searched
    If strSearchMode2 = "2" OR strSearchMode2 = "1" Then
   
        'Call the function to build the query
        strSQL = strSQL & BuildSQL ("" & strDbTable & "Downloads.Download_Name", sarySearchWord)
Else
        strSQL = strSQL & """" & strDbTable & "Downloads.Download_Name LIKE '%" & strSearchKeywords & "%'"
    End If




Microsoft OLE DB Provider for SQL Server error '80040e14'

Line 1: Incorrect syntax near 'ANDtblDownloads'.

/c4dportal2/forum/functions/3rdparty/functions_download.asp, line 1026





Replies:
Posted By: Mart
Date Posted: 23 July 2004 at 9:47am

You seem to have your SQL statement a bit confused, firstly you need to put a space on either side of the AND:

scid & " AND " & strDbTable

And at the end of that part of your SQL query you have an & when you don't need one:

strDbTable & "Downloads.D_Short AND "



Posted By: Badaboem
Date Posted: 23 July 2004 at 10:28am
Thanks mart. I've rewritten it and the error line has shifted . It still doesn't pass ''and'' for some reason.




Set rsDownload = Server.CreateObject("ADODB.RecordSet")
    strSQL = "SELECT Download_ID, Download_Preview, Download_Preview_Movie, Download_Version, D_FreeCommercial, Download_Name, D_Short, D_Added, Download_Hits, Download_SubCat, DComments "  
    strSQL = strSQL & " FROM " & strDbTable & "Downloads WHERE " & strDbTable & "Downloads.Download_SubCat = " & scid & " AND " & strDbTable & "Downloads.D_Short AND "
   
        'If the user has selected all or any words then build the where clause with the words to be searched
    If strSearchMode2 = "2" OR strSearchMode2 = "1" Then
   
        'Call the function to build the query
        strSQL = strSQL & BuildSQL ("" & strDbTable & "Downloads.Download_Name", sarySearchWord)
Else
        strSQL = strSQL & """" & strDbTable & "Downloads.Download_Name LIKE '%" & strSearchKeywords & "%'"
    End If


Microsoft OLE DB Provider for SQL Server error '80040e14'

Incorrect syntax near the keyword 'AND'.




Posted By: Semikolon
Date Posted: 28 July 2004 at 8:04am
what does the buildSQL function put out?

on the last line you can remove & """"



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net