Link to home
Start Free TrialLog in
Avatar of Eric Bourland
Eric BourlandFlag for United States of America

asked on

error with column name "x-amount"

ColdFusion 9
MS SQL Server 2012

Hi. In table "ConferenceFeeType" I would like to name a column "x-amount", because that is the name that authorize.net expects me to have for this column.

The datatype of the column is: nvarchar(50)

Strange behavior: MS SQL Server 2012 wraps the column name x-amount in brackets, like this:
[x-amount]

And ColdFusion 9 reads column [x-amount] as just "x" and so reports an invalid column, thus:

 Error Executing Database Query.
[Macromedia][SQLServer JDBC Driver][SQLServer]Invalid column name 'x'.
 
The error occurred in C:/websites/www.nnvawi.org/admin/ManageConferenceFees.cfm: line 20

18 :   <cfquery datasource="#APPLICATION.dataSource#" name="getRecords">
19 : SELECT ConferenceFeeTypeID, ConferenceFeeTitle, x-amount
20 : FROM #request.conferenceFeeTable#
21 :   </cfquery>

Can I fix this either in MS SQL Server 2012, or in my ColdFusion code?

Thanks as always. =)

Eric
Avatar of Eric Bourland
Eric Bourland
Flag of United States of America image

ASKER

I am guessing "x-amount" is a reserved column name ... doing more reading on this. Interesting topic.
SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Gary, thank you. This works:

SELECT ConferenceFeeTypeID, ConferenceFeeTitle, [x-amount]
FROM #request.conferenceFeeTable#

Open in new window


but I get an error when I apply a scope to variable x-amount, as so:

#getRecords.[x-amount]#

Open in new window


Error is:

 A CFML variable name cannot end with a "." character.
The variable getRecords. ends with a "." character. You must either provide an additional structure key or delete the "." character.

The CFML compiler was processing:

    The body of a cfoutput tag beginning on line 74, column 3.

 
The error occurred in C:/websites/www.nnvawi.org/admin/ManageConferenceFees.cfm: line 91

89 :    <td>#getRecords.ConferenceFeeTitle#</td>
90 :
91 :    <td>#getRecords.[x-amount]#</td>
Don't use it in variable names, only in the actual select
Understood. I tried this too:

 #getRecords.x-amount#

but then I get this error:

"Element X is undefined in GETRECORDS."

So it seems like ColdFusion is reading:

  #getRecords.x#
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Tried that too. =)

#getRecords[x-amount]#

Now I am getting error: "Variable X is undefined."


>>>Hyphens in variables, databases etc are generally considered bad practise
I agree 100%. This column used to be named, simply, "amount". I need to connect to a payment form on authorize.net, and have found that authorize.net requires columns with names "x-".

Thank you again for your help and ideas.

Eric
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks very much to both of you. =)

I might be making this more complicated than it needs to be.

I will set the column name back to "amount" and try to work around it in my code.

>>>That shouldn't matter what your table column names are.
You can set the variable name however you like when you pass the data to authorize.net.

Normally I agree! But I have had some trouble getting authorize.net to accept other variables. This might be entirely my own fault, however.

I will work on this some more. This has been educational.

Question: the "amount" column handles only data in US dollars --- 300.00, 100.00, and so on. Can I change the datatype to "money" or "smallmoney" in MS SQL Server 2012?

Thank you again.

Eric
In that price range use smallmoney.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> The datatype of the column is: nvarchar(50)

Oh! I just saw that. Never, never, never use "varchar" for storing numbers (or dates). You'll regret it.. take my word for it ;-)  For numbers, always use a numeric data type.
Thank you both! This clarified some things for me.

Hope your day is great.

Eric