Skip to main content
Solved

Get ID value from row

  • November 21, 2024
  • 6 replies
  • 54 views

Dennis1690
Vanguard
Forum|alt.badge.img+4

Hi, im trying to retrieve the parent_row_id from a newly added row. However @ and T1 both dont work. Anyone knows how I should fix this?

select top 1 step_nr + 1from calculation_step--where calculation_method_id = t1.calculation_method_id «order by step_nr desc

 

 

Best answer by Mark Jongeling

Okay, that clears it up. I'm afraid you will not be able to use t1. nor @something, because Default value expressions cannot do that: Data model | Thinkwise Documentation

Query - The expression used to determine the default value. The query cannot use values from a new record.

Examples: getdate() or dateadd(month, 1, getdate())

The correct way to do what you would like to achieve is using Default logic. In here you can access all the data of the current row and you will be able to set the column value.

It will most likely be similar to this:

if @cursor_from_col_id is null -- Initially
and @default_mode = 0 -- Insert
 or @step_nr is null -- If for some reason it has no value, set a value
begin
    select top 1 @step_nr = s.step_nr + 1
    from calculation_step s
    where s.calculation_method_id = @calculation_method_id
    order by s.step_nr desc
end

Hope this helps!

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

6 replies

Mark Jongeling
Administrator
Forum|alt.badge.img+23
  • Administrator
  • 3945 replies
  • November 21, 2024

Hey Dennis,

Is this a Default value expression for a Task parameter? Or for a different object?


Dennis1690
Vanguard
Forum|alt.badge.img+4
  • Author
  • Vanguard
  • 25 replies
  • November 21, 2024

For a datamodel column.


Mark Jongeling
Administrator
Forum|alt.badge.img+23
  • Administrator
  • 3945 replies
  • November 21, 2024

Can you show the datamodel? I'm trying to understand what your goal is and possibly can give an alternative.


Dennis1690
Vanguard
Forum|alt.badge.img+4
  • Author
  • Vanguard
  • 25 replies
  • November 21, 2024

calculation_method 1 - * calculation_step

When adding a new calculation step row it should take the maxvalue step_nr and add + 1. It should filter on the calculation_method_id, because steps belong to methods.

Is that sufficient enough?

Error message for reference:

 

 


Mark Jongeling
Administrator
Forum|alt.badge.img+23
  • Administrator
  • 3945 replies
  • Answer
  • November 21, 2024

Okay, that clears it up. I'm afraid you will not be able to use t1. nor @something, because Default value expressions cannot do that: Data model | Thinkwise Documentation

Query - The expression used to determine the default value. The query cannot use values from a new record.

Examples: getdate() or dateadd(month, 1, getdate())

The correct way to do what you would like to achieve is using Default logic. In here you can access all the data of the current row and you will be able to set the column value.

It will most likely be similar to this:

if @cursor_from_col_id is null -- Initially
and @default_mode = 0 -- Insert
 or @step_nr is null -- If for some reason it has no value, set a value
begin
    select top 1 @step_nr = s.step_nr + 1
    from calculation_step s
    where s.calculation_method_id = @calculation_method_id
    order by s.step_nr desc
end

Hope this helps!


Dennis1690
Vanguard
Forum|alt.badge.img+4
  • Author
  • Vanguard
  • 25 replies
  • November 21, 2024

Thanks, will see to it straight away.


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