Skip to main content
Dynamics 365 Community / Forums / Finance forum / select certain fields
Finance forum
Suggested answer

select certain fields

editSubscribe (0) ShareShare
ReportReport
Posted on by 80
 Is there a way to only select few fields without the need to put select RecId for all other un-needed table fields? (I had to select RecId because i don't need other fields and to enhance performance). But is it doable to only select 3 fields without the need to repeat recId?

while select RecId from table1 where table1.Field1 == 'XX'
    join RecId from table2 where table2.FieldX == table1.Field2
        && table2.IsField4 == NoYes::Yes
    join Field5 from table5 where table5.RecId == table3.Field6
    join Field7, Field8 from table6 where table6.Field9 == table5.RecId 
{
    info(strFmt(/Field5: %1/,table5.Field5));
    info(strFmt(/Field7: %1/,table6.Field7));
    info(strFmt(/Field8: %1/,table6.Field8));
}

maybe if i put them in view it will work.. but i want to see if i can do it in x++
  • Martin Dráb Profile Picture
    Martin Dráb 222,570 Super User on at
    select certain fields
    It doesn't matter. SQL is a declarative language - you describe what data you want; you don't define how the query will be executed (although you can influence it). Execution details are decided by SQL Server Query Optimizer.
  • Community member Profile Picture
    Community member 80 on at
    select certain fields
    Hi Martin and Muthkumaran,

    Would changing the order of the "selects" and "where" affect performance?
    for example:

    At first it was like this
    ​
                select firstonly RecId from logisticsElectronicAddress
                    where logisticsElectronicAddress.Locator == _email
                        && logisticsElectronicAddress.Type == LogisticsElectronicAddressMethodType::Email
                    join RecId logisticslocation where logisticslocation.RecId == logisticsElectronicAddress.Location
                    join RecId dirPartyLocation where dirPartyLocation.Location == logisticslocation.RecId
                    join RecId dirPerson where dirPerson.RecId == dirPartyLocation.Party
                    join RecId from hcmWorker where hcmworker.Person == dirPerson.RecId
                    join RecId hcmEmployment where hcmEmployment.Worker == hcmWorker.RecId
                        && hcmEmployment.ValidFrom <= now && hcmEmployment.ValidTo >= now;
                if(hcmWorker)
                {
                    return hcmWorker.RecId;
                } ​


    Now:
     
                select RecId from hcmWorker
                    exists join hcmEmployment where hcmEmployment.Worker == hcmWorker.RecId
                        && hcmEmployment.ValidFrom <= now && hcmEmployment.ValidTo >= now
                    exists join dirPerson where dirPerson.RecId == hcmWorker.Person
                    exists join dirPartyLocation where dirPartyLocation.Party == dirPerson.RecId
                    exists join logisticsLocation where logisticsLocation.RecId == dirPartyLocation.Location
                    exists join logisticsElectronicAddress where logisticsElectronicAddress.Location == logisticsLocation.RecId
                        && logisticsElectronicAddress.Locator == _email;​​​​​​​
    ​​​​​​​          if(hcmWorker)
                {
                    return hcmWorker.RecId;
                }


    So here I filtered at the email at the end, wasn't it better for this one to be on the first line?


    and in general can this query be enhanced more?
  • Suggested answer
    MuthukumaranAX Profile Picture
    MuthukumaranAX 2,893 on at
    select certain fields
    you can rewrite the condition like,
    write select logic for table 5 and 6 with the field list use join statement and for the other table you can use exist join
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 222,570 Super User on at
    select certain fields
    You could change the order of tables in the select statement and use exits join for table1 and table2.

Helpful resources

Quick Links

What Motivates a Super User?

We know many of you visit the Dynamics 365 Community and Power Platform…

Demystifying Copilot with Georg Glantschnig…

Industry experts answer burning questions directly from our amazing Community…

Setting Up Knowledge Sources for Copilot…

Look at how configuring a comprehensive knowledge base is crucial…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,045 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,570 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Product updates

Dynamics 365 release plans