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 :
Small and medium business | Business Central, N...
Answered

How to translate SQL "and" "or" in Business Central Query Object

(0) ShareShare
ReportReport
Posted on by 5

Hi,

I need to translate a Transact-SQL in Query Object but i don't know how to translate conditions.

For Example: 

select
m.id idMandati, m.Nome nomeMandato, coalesce(SF_DataAperturaPrimaLav(p.id),m.DataCessione) DataCessione,m.idGerp13 tipoMandato,
m.idGerp71 TipoCessionario, m.idAnagrafica idAnagCedente,
p.id, p.CodiceContabile, p.Nome, p.ContestatoDaCedente,
pc.id idCollegato, pc.idAnagrafica idAnagraficaCollegato, pc.TipoCollegato
from
mandati m, pratiche p, lavorazioni l, esiti_lista el, pratiche_collegati pc
where
m.id=911
and m.UtenteCancellazione is null
and m.id=p.idMandati and p.utentecancellazione is null
and l.idPratiche = p.id and l.UtenteCancellazione is null
and l.idEsiti_lista = el.id
and pc.idPratiche=p.id and (pc.Liberato=0 or (pc.Liberato=1 and pc.DataLiberazione>DataInizio)) #and pc.NoCR<>1
and (pc.DataCancellazione is null or pc.DataCancellazione>=DataFiltroCanc)
# and m.id = 1325
group by pc.id

Can someone help me?

Thanks

I have the same question (0)
  • Marco Mels Profile Picture
    on at

    Hello,

    Maybe this helps somehow:

    docs.microsoft.com/.../devenv-query-object

    Thanks.

  • Giuseppe Montanaro Profile Picture
    5 on at

    Hi Marco,

    thanks for your answer but i'm looking for some "complex" query and documentation doesn't really talk about that.

    Regards,

    Giuseppe.

  • Inge M. Bruvik Profile Picture
    1,105 Moderator on at

    I think it will be easier to help you if you try to explain what Business Central tables you want to access and how you want to join them.

    The sql sample you provided does not seem to come from a Business Central database.

  • Giuseppe Montanaro Profile Picture
    5 on at

    Hi,  this does not come from Business Central but i would like to transiate this into Business central code

  • Inge M. Bruvik Profile Picture
    1,105 Moderator on at

    The query function in Business Central can only access Business Central data.  So that will not work if you try to access a table outside of Business Central. Then you will have to use some kind of integration tool. F.ex use dataverse or another kind of tool.

    Are you running BC online or on prem?

    You could f.ex. look at the Virtual table functionality.

    docs.microsoft.com/.../powerplat-faq

  • Suggested answer
    YUN ZHU Profile Picture
    95,331 Super User 2025 Season 2 on at

    Hi, as far as I know, there is no tool to do this. You need to redesign Query according to your needs. In this case, you need to refer to the MS Docs provided by Marco.

    Hope this helps.

    Thanks.

    ZHU

  • Verified answer
    DAnny3211 Profile Picture
    11,397 on at

    Hi

    Giuseppe

    unfortunately the only solution is to redesign the query in AL

    Check my answer if it was helpful

    DAniele

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 > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,143

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,694 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,067 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans