I'm rather new using SQL and I have some difficulties understanding old queries and re-use it.
Especially the utility of EXECUTE and OPENQUERY commands when working on linked servers.
The code I'm using is functional because I didn't create it. But on some part I don't understand exactly how it works. I would need to understand it better to be able to create my own requests.
I've read documentation like this (https://learn.microsoft.com/fr-fr/sql/t-sql/language-elements/execute-transact-sql?view=sql-server-2017) but I still cannot undertand why EXEC is needed when working on a linked server.
EXEC('
SELECT  Cell_id,
        CAST(Trafic_Voix as float) as Trafic_Voix
        FROM OPENQUERY(myperf_ora,''
            SELECT  Cell_id,
                    MAX( (TFTRALACC+THTRALACC)/360 ) as Trafic_voix
                    FROM VIRTUO.ERI_CELL_TF_CHAN_FR_TAB_V
                    WHERE tstamp  BETWEEN '''''+@DATE_DE_DEBUT+''''' AND '''''+@DATE_DE_FIN+'''''
                    GROUP BY Cell_id                        
                                '')
    ')
If that changes anything I'm using Microsoft SQL Server Management Studio.
When I take off EXEC from the query, it doesn't work anymore and shows me error messages. I'd like to know why using this command is mandatory?
Same thing for OPENQUERY
 
     
     
    