DanSogaard
DanSogaard

Reputation: 722

Help with SQL query in C#

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.

Upvotes: 0

Views: 100

Answers (2)

Larry Lustig
Larry Lustig

Reputation: 50970

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).

Upvotes: 3

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

You are missing an as:

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

Upvotes: 1

Related Questions