Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2003

    Unanswered: SQL Select statement for column name that has two words

    I am using Visual C# to access a Pervasive v8.6 database via ODBC interface. I can't find the right syntax to Select a column whose name is two words. If the column name is only one word, I'm fine.

    Table is: Appointment
    One column name is: Appt Date
    One column name is: Length

    This C# code works when I put it in my data reader
    string queryString = "Select Length FROM Appointment";

    But if I do this,
    string queryString = "Select Appt Date FROM Appointment";
    I get a syntax errors. I've tried all kinds of combinations, just not the right one, including:

    string queryString = "Select" + "Appt Date" + "FROM Appointment";
    string queryString = "Select" ApptDate AS [Appt Date] FROM Appointment";
    string queryString = "Select" [Appt Date] = ApptDate FROM Appointment";

    I can't change the column names without crashing the program I am trying to access.

    If I go into the pervasive control center and enter this command, it works ok:
    SELECT "Appt Date" FROM "Appointment"

    thanks for your help!
    Last edited by dghundt; 04-28-06 at 21:51.

  2. #2
    Join Date
    Dec 2001
    Provided Answers: 6
    You need to surround the field name with double quotes in C# too.
    For example:
    string queryString = "SELECT \"Appt Date\" FROM Appointment"
    Mirtheil Software
    Certified Pervasive Developer
    Certified Pervasive Technician
    Custom Btrieve/VB development
    I do not answer questions by email. Please post on the forum.

  3. #3
    Join Date
    Oct 2003
    Thanks, your rock!

    I used the following string which works well. As you point out, the \ prior to the quote is an escape character that tells C# to use the " literally instead of a delimeter for a string. I added \r\n which gave me a new line.

    "SELECT \"Appt Date\", \"Appt Time\", \"Home Phone\"\r\nFROM Appointment"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts