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)

Translating T-SQL query to x++

(1) ShareShare
ReportReport
Posted on by 1,400

Hi guys, I'm trying to convert the following T-SQL query to x++:

INSERT INTO 
TABLE1
(COLUMN1, COLUMN2, COLUMN3)
SELECT
@VARIABLE1 AS COLUMN1,
@VARIABLE2 AS COLUMN2,
TABLE2.COLUMN3 AS COLUMN3
FROM 
#TABLE2 TABLE2 
LEFT JOIN TABLE1 WITH (NOLOCK) ON
TABLE1.COLUMN1 = TABLE2.COLUMN1
AND TABLE1.COLUMN2 = @SOMEVARIABLE
WHERE
TABLE1.COLUMN3 IS NULL

but when I wrote it in x++, it came out like this:

while select column3
from table2
where table1.column3 == ''
outer join table1 
where table1.column1 == table2.column1
&& table1.column2 == someVariable
{
table1.column1 = variable1;
table1.column2 = variable2;
table1.column3 = table2.column3;
insertRecordList.Add(table1);
}
insertRecordList.insertDatabase();


Which I'm pretty sure it's wrong because it won't filter on that first 'where' clause, as the table buffer is still empty at that point (I believe).

What would be the appropriate way to translate that to x++? Am I approaching this the wrong way?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,697 Most Valuable Professional on at

    Are you aware of insert_recordset? It would be closer to the original SQL code.

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
Priya_K Profile Picture

Priya_K 4

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 3

#3
Scott_itD Profile Picture

Scott_itD 2 Community Manager

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans