Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9125839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:53:50+00:00 2026-06-17T06:53:50+00:00

I am trying to use a variable as the column field in the SQL.

  • 0

I am trying to use a variable as the column field in the SQL. However when I run the code I get the following error:


Microsoft VBScript compilation error '800a0408'

Invalid character

/junk/dbresults.htm, line 25

DECLARE @cat char(20)
--------^

The code is below:

<%
    Dim connectString, connect, conDB, con
    connectString = "Driver={Microsoft Text Driver (*.txt; *.csv)}; DBQ=" & Server.MapPath("data")
          src_abn = Request.QueryString("abn")
          src_cat = Request.QueryString("cat")
    set connect = Server.CreateObject("ADODB.connection")
    connect.open connectString

    DECLARE @cat char(20)
    DECLARE @dynamicsql char(1000)

    SET @cat = src_cat;
    SET @dynamicsql = "SELECT * FROM cont.csv WHERE @cat='Yes'"

    if src_abn = "all" then
    conDB = EXEC (@DynamicSQL)  
    else
    conDB = "SELECT * FROM cont.csv WHERE ucase(abn) LIKE ucase('%"+src_abn+"%')"   
    end if

    set con = connect.execute(conDB)
%>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:53:51+00:00Added an answer on June 17, 2026 at 6:53 am

    I’m not positive what you’re trying to do, but you can’t run SQL Syntax (i.e. DECLARE @cat…) with classic ASP. Are you trying to do something like this?

    <%
        //Request your variables
        src_abn = Request.QueryString("abn")
        src_cat = Request.QueryString("cat")
    
        Dim connectionString, dbConn, rsResults, strSQL
    
        //Setup your connection
        connectionString = "Driver={Microsoft Text Driver (*.txt; *.csv)}; DBQ=" & Server.MapPath("data")
        set dbConn= Server.CreateObject("ADODB.Connection")
        dbConn.open connectionString
    
        //Create your sql statement
        if src_abn = "all" then
            strSQL = "SELECT * FROM cont.csv WHERE " & src_cat & "='Yes'"
        else
            strSQL = "SELECT * FROM cont.csv WHERE ucase(abn) LIKE ucase('%" & src_abn & "%')"   
        end if
    
        //Create your results
        set rsResults = Server.CreateObject("ADODB.Recordset")
        rsResults.open strSQL, dbConn
    
        //Loop through your results
        While Not rsResults.EOF
    
            rsResults.MoveNext
        Wend
    
        //Closes results and connection
        rsResults.Close
        dbConn.Close
    %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use a variable to get a function in a extended
I'm a newbie to PHP/SQL and I am trying to use a variable within
I am trying to use a C# SQL search and then get a Boolean
I am trying to use variable in different function, I want to set global
I'm trying to use my variable in all files of my program. this is
I am trying to use Unicode variable names in g++, but it does not
I'm trying to use a global variable. I've declared it as global to begin
I am trying to use a C++11 Lambda to initialize a const member variable
I'm trying to use usort() and leverage a global variable inside its function scope,
I'm trying to use WolframAlpha to solve for a variable. I have u(k, r)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.