If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Pervasive.SQL > SQL Select statement for column name that has two words

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-28-06, 20:10
dghundt dghundt is offline
Registered User
 
Join Date: Oct 2003
Posts: 18
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!
david

Last edited by dghundt; 04-28-06 at 20:51.
Reply With Quote
  #2 (permalink)  
Old 04-28-06, 22:52
mirtheil mirtheil is offline
Registered User
 
Join Date: Dec 2001
Posts: 1,026
You need to surround the field name with double quotes in C# too.
For example:
Code:
string queryString = "SELECT \"Appt Date\" FROM Appointment"
__________________
Mirtheil Software
Certified Pervasive Developer
Certified Pervasive Technician
Custom Btrieve/VB development
http://www.mirtheil.com
I do not answer questions by email. Please post on the forum.
Reply With Quote
  #3 (permalink)  
Old 04-29-06, 09:09
dghundt dghundt is offline
Registered User
 
Join Date: Oct 2003
Posts: 18
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"
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On