IT SOLUTIONS
Your TECHNOLOGY partner! 
 
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post:

Enter your name and security key.

Your Name:
Today's security key = P246A
Enter key:
Write a Comment...

Comments

1 Comments.
Share a thought or comment...

jmalone68
Comment 1 of 2

Thanks SO much for that.

The previous DBA here can be held responsible for the untimely end of dozens of kittens.

Grrrr - It's caused me nothing but heartache.

Cheers,

John

Posted 30 months ago


Wes Peterson
Comment 2 of 2

John,

Sorry to hear about the kittens. Frown

As a developer that often has to maintain others' code, it's maddening to run into database table and column names that include spaces.

It's tempting to blame whoever designed the database schema, but when I think about that, I have a better target for my ire: the makers of databases that allow spaces in entity names to begin with.

What are they thinking? I have an old motto: Just because a thing can be done, doesn't mean it should be done. So the clever database designers could make spaces legal. Great. But at what cost to others down the road?

Say we need to name a data column. Is "Last Name" really any better a name than "LastName?" If so, I'd really like to understand why.

Posted 30 months ago

Commenting on...

[View/Review Post]
Title: Paradox, .NET, and the Wicked Back-Tick
By: Wes Peterson

Using spaces within database column names may be "legal," but that doesn't mean it won't make your life harder. It's legal in Paradox tables and most database systems but you might want to avoid using spaces. Here's why - and one way to use spaces if you're using Paradox tables under .NET.

Spaces in column names: What a travesty. They may be legal, but they just cause trouble. To paraphrase my colleague Andy Kern, "Every time a DBA puts a space in a column name, God kills a kitten."

Virtually every incarnation of SQL has syntax for dealing with column names that contain spaces. Some want the column name in single quotes: 'My Column'

Some want it surrounded by square brackets: [My Column]

To make things more fun, some require the column reference to be preceded by the table name: MyTable.[My Column]

Now suppose you're trying to use .NET to access and manipulate data in Paradox tables, and spaces appear in some of the field names.  What syntax do you use to reference such columns in your SQL?

I'll start by saying that it may depend on the ODBC driver you've chosen, but that quickly becomes a non-issue when you realize that the Intersolv Paradox ODBC drivers are the most reliable at playing nicely with .NET. Don't even start without one.

The column delimiter you want isn't a quote, a single-quote (apostrophe), or brackets. It's an arcane little bugger called the "back-tick" or, more properly, the grave.  On most keyboards it appears on the same key as the tilde character, (~).  It's like a backwards apostrophe.

So a simple SQL statement might look like this:

SELECT `My Field' FROM MyTable

You can verify this by using the query builder in Visual Studio. 

I didn't find it there for a dumb reason: Early in my first .NET project involving Paradox tables, I'd tried the various Paradox ODBC drivers from Microsoft. With those, the query builder didn't work - so I'd given up on it - and went Googling for the proper SQL syntax. My searches came back with many hits, none of which disclosed the back-tick.  Grrrrr.

So there you have it: If you need to write SQL that references columns with embedded spaces, if you're working in .NET, and if you're using the Intersolv Paradox ODBC driver, the back-tick (grave) is what you want.

-
  Load Time=less than 1 second.
 
Print This

KB Post Options:
-
 
Have a question? Need our services? Contact us now.
--Mike Prestwood

Call: 916-726-5675

email: info@prestwood.com


©1995-2013 Prestwood IT Solutions.   [Security & Privacy]   Made in the U.S.A..   No H1-B.   No offshoring.