web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

I can pass parameter to Computed Column, or get the field value ?

(0) ShareShare
ReportReport
Posted on by 578

I need filter the field value in a computes column, is possible?

cap09.PNG

Are very much select, my other option is create un store procedure

thanks in advance

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mea_ Profile Picture
    60,286 on at

    Method for a computed column should return you SQL statement that would be injected in your SQL view definition. You cannot use any selects or logic there. However, if range you want to use is a constant or a field from the same table then you can use it in the where statement. Usually it's easier to build sub select in SSMS first, test it and then convert to computed column.

  • ismaelivan Profile Picture
    578 on at

    I already did it by sql, but I need a DECLARE and it is not allowed in the column. There are 3 queries, Table A does not bring results, I look in Table B, Otherwise in Table C

  • Mea_ Profile Picture
    60,286 on at

    Could you please provide more details? Like why do you need DECLARE  ?

  • ismaelivan Profile Picture
    578 on at
     


    STR VALUE = SYSCOMPUTEDCOLUMN::RETURNFIELD(MYFIELD);

    SELECT FIELD1 FROM TABLEA WHERE TABLEA.FIELD == VALUE;
    IF(TABLEA) { RETURN SYSCOMPUTEDCOLUMN::RETURNLITERAL(TABLEA.FIELD1); } ELSE { SELECT FIELD1 FROM TABLEB WHERE TABLEB.FIELD == VALUE; IF(TABLEB) { RETURN SYSCOMPUTEDCOLUMN::RETURNLITERAL(TABLEB.FIELD1); } ELSE { SELECT FIELD1 FROM TABLEC WHERE TABLEC.FIELD == VALUE; IF(TABLEC) { RETURN SYSCOMPUTEDCOLUMN::RETURNLITERAL(TABLEC.FIELD1); } ELSE { RETURN SYSCOMPUTEDCOLUMN::RETURNLITERAL(''); } } }

    i like do this. depending on the value of VALUE, I consult in different tables

    and in sql it would be something like that

    DECLARE @MYVAR VARCHAR(20);
    SELECT @MYVAR = FIELD1 * FROM TABLEA
    IF(@MYVAR=='')
    BEGIN
     SELECT @MYVAR = FIELD1 * FROM TABLEB
     ....
    END


  • Suggested answer
    Mea_ Profile Picture
    60,286 on at

    You dont need declare, it can be done using "case" here is an example of SQL statement getting data from different tables:

    select itemId,

            case itemId

                when 'BRMF010' then (select top 1 SalesId from SALESLINE where itemId = itemId)

                else (select top 1 Purchid from PURCHLINE where itemId = itemId)

            end myColumn

    from INVENTTABLE

  • ismaelivan Profile Picture
    578 on at

    Thanks But how i can validate if the first table has 0 rows, search in second table?

  • ismaelivan Profile Picture
    578 on at
    select case when exists (select 1 from TableA where ...) 
              then (select top 1 SalesId from TableA where ...)
              else (select case when exists (select 1 from TableB where ...) 
    		then (select top 1 SalesId from TableB where ...)
    		else (select case when exists (select 1 from TableC where ...) 
    			then (select top 1 SalesId from TableC where ...)
    			else ('')
    			end)
    		end)
              end 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 16

#2
GiacomoRovai Profile Picture

GiacomoRovai 4

#3
Douglas Noel Profile Picture

Douglas Noel 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans