Jun 12 2020 06:56 AM - edited Jun 12 2020 07:17 AM
Hi.
I try connect exel to mssql serwer. Connections work great except WHERE clause.
This is my simple query :
SELECT * FROM EMPLOYERS WHERE ID > 100
How I can pass where condition in this case 100 from exel cell ?
Til now work "?" and then exel ask where is parameters but now this method stops working.
I found this :
let
Źródło = Excel.CurrentWorkbook(){[Name="Tabela1"]}[Content],
#"Zmieniono typ" = Table.TransformColumnTypes(Źródło,{{"ID", Int64.Type}}),
IDFirmy = #"Zmieniono typ"{0}[ID],
Źródło2 = Sql.Database("localhost\sqlexpress2019", "SZKOLENIE", [Query="SELECT * FROM EMPLOYERS WHERE ID > 100"]),
#"Przefiltrowano wiersze" = Table.SelectRows(Źródło2, each ([ID] = IDFirmy ))
in
#"Przefiltrowano wiersze"
work ok but filtering is perform in exel not in sql so performance may be low.
Jun 13 2020 06:56 AM
If ID in some named cell as here
you may use it in query like
let
GetID = Excel.CurrentWorkbook(){[Name="ID"]}[Content][Column1]{0},
queryString="SELECT * FROM EMPLOYERS WHERE ID > " & Text.From(GetID)
//Źródło2 = Sql.Database("localhost\sqlexpress2019", "SZKOLENIE", [Query=queryString])
in
queryString