Skip to main content
Solved

calculated column t1?


Forum|alt.badge.img+4

Do you need to use t1 with the calculated column type?
 

I have the following calculated field code : btw_percentage / 100 + 1.00
However when I tried to add t1. to it. The database gave an error. 
But the code as it is written above doesn't work.

Does anyone know how to handle this?


 

Best answer by Mark Jongeling

SQL server will see 21 / 100, for example, as 0, then + 1.00 is 1.00. This is not intended. When needing calculations like this, you'll need to ensure the tax percentage is of type Numeric (or similar).

View original
Did this topic help you find an answer to your question?
This topic has been closed for comments

5 replies

Mark Jongeling
Administrator
Forum|alt.badge.img+23

Hi Maarten,

Specifying t1 is not needed as the column is in the context of the table already. No other tables are available, thus always selecting out of the same table.

What is exactly not working? 

One thing I can think of is that btw_percentage has a datatype of type INT. This will not go well with dividing and such. 


Forum|alt.badge.img+4
  • Author
  • Vanguard
  • 24 replies
  • August 26, 2022

@Mark Jongeling  btw_percentage is indeed of the datatype int


Mark Jongeling
Administrator
Forum|alt.badge.img+23
  • Administrator
  • 3940 replies
  • Answer
  • August 26, 2022

SQL server will see 21 / 100, for example, as 0, then + 1.00 is 1.00. This is not intended. When needing calculations like this, you'll need to ensure the tax percentage is of type Numeric (or similar).


Freddy
Forum|alt.badge.img+16
  • Thinkwise Local Partner Brasil
  • 529 replies
  • August 26, 2022

As a rule:

  • Expression fields user t1.column_name
  • Calculated columns (no prefix) column_name
  • Calculated columns (via function) @column_name

As you to your code, when it's an INT you sometimes need to push decimals, I guess in this case you would like to make from 21% a factor 1,21 right?

(100.0 + btw_percentage) / 100.0 

If above still gives an error you can always cast btw_percentage as a decimal(5,2) for example. 


Jeroen van den Belt
Administrator
Forum|alt.badge.img+9

Please see this related idea, which will be available in the next platform release: 

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings