Forum Discussion

powerbidev123's avatar
powerbidev123
Icon for Solution Sage rankSolution Sage
1 year ago
Solved

Issue while using stored procedure in SQL server database

  Hi community,   Is there a way to fix this because manually inserting the customerid works but when I try to make it parameterized then it gives the above error   Any kind of suggestion ...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi powerbidev123 ,

     

    Thanks for the reply from girishthimmaiah .

     

    Assuming that your

    Server = X

    Database = Y

    Table name = Z

     

    The sample SQL query is (as if you put it on SSMS)

    select *
    from z
    WHERE [customerid]=2

     

    The conversion to M-code is:

    let
        Source = Sql.Database("vm1", "TutorialDB", [Query="select *#(lf)from Customers#(lf)WHERE [customerid]=2#(lf)"])
    in
        Source

     

    Now, if you want to pass parameters to the where clause as Parameter1, (e.g. Parameter1 =2) make sure they are text first.

     

    You can create a custom query as follows:

    let
        Source = Sql.Database("x", "y", [Query="select *#(lf)from z#(lf)WHERE [customerid]="&Parameter1&"#(lf)"])
    in
        Source

     

    If you have any other questions please feel free to contact me.

     

    Best Regards,
    Yang
    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
    If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!