views:

810

answers:

2

I have a format file where I want one of the columns to be "group". I'm auto-generating the format file and a client wants to upload a file with "group" as one of the columns. I could restrict it so they can't use SQL keywords, but then I need a function to determine if a column name is a SQL keyword, so I'd like to support the user being able to name their clients however they want. I'm wondering if this is possible. I tried using brackets, but that didn't appear to work. My file looks like:

8.0
1
1 SQLCHAR 0 0 "\r\n" 1  [group] SQL_Latin1_General_CP1_CI_AS
+1  A: 

I tested this out several different ways on SQL 2005 SP2 (target databases in both compatibility modes 80 and 90) and it works OK for me using the SQL 2005 version of bcp.

However, I also tested it with the SQL 2000 version of bcp, and that failed with

Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near the keyword 'group'.

which I guess is what you're getting.

Are you able to upgrade the system where you're running bcp to use the SQL 2005 client tools?

If you believe that you have already upgraded, check your PATH environment variable to confirm that

C:\Program Files\Microsoft SQL Server\90\Tools\binn\

(adjusted for your installation) appears before

C:\Program Files\Microsoft SQL Server\80\Tools\BINN

otherwise the SQL 2000 command line tools will be used in preference to the SQL 2005

Ed Harper
A: 

On MS SQL, you can use a SQL Keywork as a column name if you put it in quotation.

Example: SELECT id, "group" FROM myTable

Hapkido