Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Database table column name contains # sign

New Here ,
Jun 01, 2011 Jun 01, 2011

I need to query a database table (I cannot rename the column names) in where the column name contains a # sign (PRICE_OR_DISC#1). This causes CF to crash because of the # sign. Is there a way to query a column name that contains a # sign?

1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 01, 2011 Jun 01, 2011

Double-hash escapes a hash within CF.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 01, 2011 Jun 01, 2011

Yes, I tried that but I need to keep one hash (#) because it is part of the column name. Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 01, 2011 Jun 01, 2011

Your post is too vague.  What did you try and what was the result?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 01, 2011 Jun 01, 2011

I have to query an SQL server database table that I do not administer and the table column/field name cannot be changed. The column/field name I need to pull data from includes a # sign in the column/field name (PRICE_OR_DISC#1). See query below.

When I run the query, ColdFusion errors because there is a single # sign encountered. Being that I cannot change the column/field name to remove the # sign I am trying to find if there is a workaround for this situation. Does this make more sense?

  <cfquery name="MyQuery" datasource="MyDataSource">
   SELECT
    ib.ID_Item,
    ib.DESCR_1,
    ib.DESCR_2,
    ib.CODE_CAT_PRDT,
    tpi.PRICE_OR_DISC#1 AS Price,
    tpi.PREC_PRICE
     
   FROM MyDB ib

   INNER JOIN TABLES_PRICE_ITEM tpi ON ib.ID_Item = tpi.ID_Item

   WHERE
    ib.ID_Item = '#form.ID#'
   </cfquery>

Thanks for your help!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 01, 2011 Jun 01, 2011

Have you tried putting the column name in square brackets, as well as doubling up the hash-marks?  The

square brackets are for SQL because of the special character in the name (or when the name is a SQL reserved word).  The doubled-up hashmarks are for CF so that it will pass the single hashmark to SQL. 

-reed

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jun 01, 2011 Jun 01, 2011

>> ColdFusion errors because there is a single # sign encountered.

Right. That is why Owain suggested you escape the # sign by using two # signs, not just one. Did you try that, because it is not in your sql code?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 01, 2011 Jun 01, 2011
LATEST

My apologies and thanks to all. I tried "tpi.PRICE_OR_DISC##1," again, which I was positive that tried more than once and it works now. Obviously operator error on my part.

Thanks so much for helping me to the solution!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources