Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Translating T-SQL query to x++

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

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,214 Most Valuable Professional on at
    RE: Translating T-SQL query to x++

    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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans