Skip to main content
Dani Szwarc
Inspiring
January 18, 2012
Answered

Coldfusion and MS SQL

  • January 18, 2012
  • 1 reply
  • 1377 views

Hello community, a client of mine just moved their database from Pervasive to MS SQL. I created an intranet that was accessing the Pervasive database with no problems.

The problem I have is something weird that is happening when querying the new database.

In one particular table the name a column for description "DESC", which is a MS SQL keyword. I'm able to retrieve the data from it if I use quotation marks.

<cfquery datasource="test" name="equipo">

        SELECT "DESC"

        FROM ICITEM

</cfquery>

So far so good.

Now, if I want to retrieve another column called ITEMNO my query looks like this:

<cfquery datasource="test" name="equipo">

        SELECT ITEMNO, "DESC"

        FROM ICITEM

</cfquery>

It also works.

However, when I try to get a different column called FMTITEMNO, which exists, i get an error using this query:

<cfquery datasource="test" name="equipo">

        SELECT FMTITEMNO, "DESC"

        FROM ICITEM

</cfquery>

Error:

If I try just that column alone, without the "DESC" column, it works:

<cfquery datasource="test" name="equipo">

        SELECT FMTITEMNO

        FROM ICITEM

</cfquery>

This is my first time working with MS SQL and I think it could be something related to the syntax.

If someone understands what could be happening it would be a great help.

Thank you so much!

This topic has been closed for replies.
Correct answer Reed_Powell-ttnmOb

That means that there is a problem with your database.  If you google "SQL Server Error 824" you'll see a number of references that will give you steps for determining what the problem is.  If you have someone who acts as the DBA for your MS SQL server, you're going to need their involvement.

-reed

1 reply

Inspiring
January 19, 2012

In MS SQL, if you need to reference a column with an illegal name, you need to put the column name in square brackets and the alias the name so that you can reference it in the query resultset.For example, I have a table that is created via an import from an Excel spreadsheet, and the spreadsheet happens to have a leading space in the column name as well as in the middle of the column name:

<cfquery name="PropertyList" datasource="Feeds">

  SELECT Resort, [ Resort Name] AS resort_name, [ country code] AS country_code

  FROM xxx

</cfquery>

I then reference those columns in the CF code as Feeds.resort_name and Feeds.country_code

-reed

Dani Szwarc
Inspiring
January 19, 2012

Thank you Reed, but I still get the same error when trying to get both results. However, they work individually.

I'm scratching my head with this.

Reed_Powell-ttnmObCorrect answer
Inspiring
January 19, 2012

That means that there is a problem with your database.  If you google "SQL Server Error 824" you'll see a number of references that will give you steps for determining what the problem is.  If you have someone who acts as the DBA for your MS SQL server, you're going to need their involvement.

-reed