Forum Discussion
Pass List Value through SQL Statement without Parameter
- Anonymous8 years ago
Hi v-frfei-msft,
I found this description which was worked for me:
https://www.excelguru.ca/blog/2016/04/28/pass-parameters-to-sql-queries/
I needed to add in a couple of other fields and do some moving around but it's working great now.
Thanks for the help.
- Anonymous7 years ago
Hi Romain_FOURNIER ,
I figured out a way around it - I created a separate Day, Month and Year filter which I then passed through my SQL statement as numbers to make the date field. I've detailed what I did in this other thread:
Thanks,
MarkJames
Hi Anonymous,
I make an example for your reference.
1.Import an excel file to desktop add a custom column based on id column then create the parameter in power query.
M code in the power query is like this for step1.
(para as text) as table =>
let
Source = Excel.Workbook(File.Contents("D:\Case\20180810\New Microsoft Excel Worksheet.xlsx"), null, true),
Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(Sheet1_Sheet,{{"Column1", type text}}),
#"Removed Top Rows" = Table.Skip(#"Changed Type",1),
#"Renamed Columns" = Table.RenameColumns(#"Removed Top Rows",{{"Column1", "account name"}, {"Column2", "id"}}),
#"Filtered Rows" = Table.SelectRows(#"Renamed Columns", each ([account name] = para)),
#"Added Custom" = Table.AddColumn(#"Filtered Rows", "Custom", each "'" &[id] &"'")
in
#"Added Custom"
2.Then we can add some steps in the Advanced editor.
(para as text) as table =>
let
Source = Excel.Workbook(File.Contents("D:\Case\20180810\New Microsoft Excel Worksheet.xlsx"), null, true),
Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(Sheet1_Sheet,{{"Column1", type text}}),
#"Removed Top Rows" = Table.Skip(#"Changed Type",1),
#"Renamed Columns" = Table.RenameColumns(#"Removed Top Rows",{{"Column1", "account name"}, {"Column2", "id"}}),
#"Filtered Rows" = Table.SelectRows(#"Renamed Columns", each ([account name] = para)),
#"Added Custom" = Table.AddColumn(#"Filtered Rows", "Custom", each "'" &[id] &"'"),
keylist= Text.Combine(#"Added Custom"[Custom],","),
select1="SELECT * FROM servername.databasename.dbo.tablename WHERE id IN (" & keylist & ")",
Source1 = Sql.Database("servername ", "databasename", [Query=select1])
in
Source1
3.Then we can get the excepted result once we invoke the parameter.
If you still have questions, please share sample data of your table and post SQL query here.
Regards,
Frank
- Anonymous8 years agoNot applicable
Hi v-frfei-msft,
I found this description which was worked for me:
https://www.excelguru.ca/blog/2016/04/28/pass-parameters-to-sql-queries/
I needed to add in a couple of other fields and do some moving around but it's working great now.
Thanks for the help.