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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Converting SQL query to D365FO view

(0) ShareShare
ReportReport
Posted on by 86

Hi Folks,

Any idea?. To convert this SQL query to VIEW in D365FO.

Requirment: From child table, system should return only first record.

Tried with FIRSTONLY or FIRSTFAST properties in view. Not working its seems.

Note: In sql query, it was working. but not able to accomodate same on D365FO view.

Query:

SELECT t1.WAVEID, t2.ACCOUNTNUM, t2.DELIVERYNAME
FROM WHSSHIPMENTTABLE AS t1 LEFT JOIN (
SELECT *, ROW_NUMBER() OVER(PARTITION BY WAVEID ORDER BY ACCOUNTNUM Asc) AS RowNo
FROM WHSSHIPMENTTABLE
) AS t2 ON t1.WAVEID = t2.WAVEID AND t2.RowNo=1
where t1.LOADDIRECTION = 2 and t1.WORKTRANSTYPE = 2 and t1.WAVEID != ''
Group by t1.WAVEID, t2.ACCOUNTNUM, t2.DELIVERYNAME

Output:

D365FO (Output) View output
Customer WaveId
CI001 WT1000000282
CI002 WT1000000282
CI003 WT1000000282
CI004 WT1000000282
CI005 WT1000000282
CI006 WT100000998
CI007 WT100000998
SQL (Excepted)
Customer WaveId
CI001 WT1000000282
CI006 WT100000998

Thanks in advance.

I have the same question (0)
  • Verified answer
    André Arnaud de Calavon Profile Picture
    300,911 Super User 2025 Season 2 on at

    Hi Sangeeth,

    You can use a virtual field in View. The data will then be retrieved with a method on the view where you can use T-SQL statements. You can search on the internet for more examples.

    One example: devmusings.blog/.../

  • Suggested answer
    Sangeeth R Profile Picture
    86 on at

    Thanks Andre. Its working fine now. After converting to computed column method.

    T-SQL statment like this way.

    return strFmt(@'select top 1 WHT.ACCOUNTNUM from WHSSHIPMENTTABLE as WHT

                               where WHT.WaveId = %1 order by WHT.RECID asc',waveId);

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Hi Sangeeth,

    just double checking - did you intend the column to always fetch a fixed wave id? The computed column is created during database synchronization, and whatever was in your "waveid" variable at that point (we can't see from your code if it's empty or if you hardcoded some value) will be stored in the computed column definition. So it's not using different wave ids dynamically during runtime.

  • Sangeeth R Profile Picture
    86 on at

    Yes. Cross checked all data. On computed column view method Wave Id fetches dynamically during runtime.

    See

    View design in sql:

    SELECT   WAVEID, DATAAREAID, PARTITION, 1010 AS RECID, CAST

                    ((SELECT   TOP (1) ACCOUNTNUM

                    FROM      dbo.WHSSHIPMENTTABLE AS WHT

                    WHERE    (WAVEID = T1.WAVEID)

                    ORDER BY RECID) AS NVARCHAR(20)) AS ACCOUNTNUM, CAST

                    ((SELECT   TOP (1) DELIVERYNAME

                    FROM      dbo.WHSSHIPMENTTABLE AS WHT

                    WHERE    (WAVEID = T1.WAVEID)

                    ORDER BY RECID) AS NVARCHAR(100)) AS CUSTOMERNAME

    FROM     dbo.WHSSHIPMENTTABLE AS T1

    WHERE   (LOADDIRECTION = 2) AND (WORKTRANSTYPE = 2) AND EXISTS

                    (SELECT   TOP (1) ' x ' AS Expr1

                    FROM     dbo.WHSWAVETABLE AS T2

                    WHERE   (T1.WAVEID = WAVEID) AND (T1.DATAAREAID = DATAAREAID) AND (T1.PARTITION = PARTITION))

    GROUP BY WAVEID, DATAAREAID, PARTITION

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans