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 :
Microsoft Dynamics AX (Archived)

Need to insert SQL Query in the Expression where it says "Set expression for: Value"

(0) ShareShare
ReportReport
Posted on by

Hello Gurus!

I'm trying to use/ add an SQL query into a report form I'm creating to see employee's duration in a specific departments. 

Scenario: Employees work in an organization but can switch between departments. I need the duration of each employee in each department. Basically, deducting the EndDate from StartDate but using DATEDIFFerence within the given DataSet.

The query I'm using works in SQL Server 2014 works fine. I want to use that query as a Column Value in the Expression using Visual Studio Design page.

Even though the query works, Dynamics AX 2012 R3, I kept getting:

1. SELECT is invalid...

2. CAST is invalid...(when I remove the SELECT)

3. Without the "=" (equal sign), all the query syntax just displays on the column when I run it.

Does anyone know I maybe able to use my own query instead of selecting Categories and Items from the Expression dialogue?

= Select (cast(datediff(yy, Fields!startDate.Value, Fields!endDate.Value) as varchar(4)), + ' Years, ' +
cast(dateDiff(mm, dateAdd(yy, Fields!dateDiff.Value(yy, Fields!startDate.Value, Fields!endDate.Value),
...
+ ' Days' as EmploymentDuration
From [TheTableName]

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Thanks for the quick reply. Is there any other way to get the following query to get me the years, months and days?

    This is what I inserted into the Expressions to get me the total days an employee is "Employed" for each person.

    =DateDiff("y", Fields!StartDate.Value, Fields!EndDate.Value).

    It provides just the days (i.e., 365, 397, 1115 etc...)

    Is there a way I can present them as (1 Year, 0 months, 0 Days || 1 Year, 1 Month, 2 Days...)?

    Thanks!

  • Community Member Profile Picture
    on at

    Thanks Crispin, unfortunately no. It'll have to be my next task from what I have read in the past 20 minutes or so.

    How come it seams so simple!? It's really annoying considering how much time I spent.

    Crispin, do you have any recommendations/suggestions to where I might be able to accomplish this faster?

    For some reason, I thought, since I got the dates, I could just divide it up by 365 to get the year, mod to get the month(/12) and another mod to get the dates (/30) or similar query.

    I really would appreciate if I get any help!

    Thanks

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans