0

I'm trying to rename the columns. The syntax should be the column name between double quotes incase of two words, like this:

SELECT p_Name "Product Name" from items

So I'm trying to do it in C# code like this:

string sqlqry1 = "SELECT p_Name \"Prodcut Name\" from items";

But I get an error:

Syntax error (missing operator) in query expression 'p_Name "Prodcut Name"'.

It seems am having somthing wrong with the quotes, but I can't figure out.

3
  • 3
    Which database: MySQL? SQL Server 2005? 2008? Commented Mar 20, 2010 at 15:44
  • I'm surprised people jump in to answer without knowing what database server it is Commented Mar 20, 2010 at 15:47
  • I'm using MS Access, I should have mentioned, my bad. Commented Mar 20, 2010 at 15:59

2 Answers 2

3

You don't specify what database you're using. Different DBMSes use different quoting systems for identifiers (like column names). Try:

 SELECT p_Name AS [Product Name] FROM items

or

 SELECT p_Name AS `Product Name` FROM items

which are two common systems. Also, use the AS specifier even though some DBMSes allow you to leave it out.

(PS: In the second example, the quote character is the backtick, generally on the same key as the tilde (~) on US keyboards).

Sign up to request clarification or add additional context in comments.

2 Comments

Always a pleasure to be of help.
@gbn: I tried the first statement and its working without any errors: SELECT p_Name AS [Product Name] FROM items
1

You are missing an as:

string sqlqry1 = "SELECT p_Name as \"Prodcut Name\" from items";

5 Comments

Rubbish. it's optional. See msdn.microsoft.com/en-us/library/ms176104.aspx it says ...[ [ AS ] column_alias ]...
@gbn: Why are you citing microsoft docs when the OP did not specify what database he is using?
@Larry Lustig: care to bet? Does every DBMS require AS too?
Not "every" DBMS, but some do. Why introduce possible complications while debugging?
@gbn: you're right. I don't know any database server that requires "as". DB2, MySql, Sqlite, SqlServer, Oracle, ... They all don't care

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.