Forum Discussion

fsim's avatar
fsim
Responsive Resident
2 years ago
Solved

connection function and error in the argument passed

hello HiveMind In our infrastructure, I have multiple environments. For each one, I have a data server whose name changes, as well as 4 databases (which are Bronze_crm, Bronze_FO, Silver, and Gold) ...
  • fsim's avatar
    2 years ago

    if Value.Is(qury)  is the source of the error. (It took me 2 days to figure it out and, guess what, co-pilot didn't spot it)
    I replaced it by qury <>"" and it works. 
    enjoy the 
    (DB as text, optional qury as text) =>
    let
    ParametreTrouve = Table.SelectRows(connectors, each [env] = ENVDYN),
    P_Server = if Table.RowCount(ParametreTrouve) > 0 then ParametreTrouve{0}[Server] else null,
    P_DB = if Table.RowCount(ParametreTrouve) > 0 then Record.Field(ParametreTrouve{0}, DB) else null,
    connection =
    if qury <>"" then
    Sql.Database(P_Server, P_DB ,[Query=qury])
    else
    Sql.Database(P_Server, P_DB)
    in
    connection