cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Shiva799 Frequent Visitor
Frequent Visitor

Error converting data type varchar to date.

Hi, I'm trying to write an m code for an sp to take parameters dynamically. It goes as let Source = Sql.Database("servername", "dbname", [Query="exec [SP_GetReport] 'Status','All','Frequency','BusinessDate'"]) in Source But it gives this error DataSource.Error: Microsoft SQL: Error converting data type varchar to date. Details: DataSourceKind=SQL DataSourcePath=blccnamist;MI_FLATTENED_VIEW Message=Error converting data type varchar to date. Number=8114 Class=16 Also 'All' is not a parameter but value and date format accepted by sp is yyyy-mm-dd i also tried formatting the business date parameter to Date.FromText(Text.From([BusinessDate])) or Date.FromText(Text.From(['BusinessDate'])) or Date.FromText(Text.From(['&BusinessDate&'])) or "Date.FromText(Text.From([BusinessDate]))" or '&Date.FromText(Text.From([BusinessDate]))&' but its still not working I hope someone might be able to tell me where exactly I'm going wrong Thanks in advance
2 REPLIES 2
Microsoft v-ljerr-msft
Microsoft

Re: Error converting data type varchar to date.

Hi @Shiva799,

 

Could you try using the query below to see if it works? Smiley Happy

let 
bDate = BusinessDate Source = Sql.Database("servername", "dbname", [Query="exec [SP_GetReport] 'Status','All','Frequency','"&bDate&"'"]) in Source

 

Regards

Shiva799 Frequent Visitor
Frequent Visitor

Re: Error converting data type varchar to date.

Nope Expression.Error: We cannot apply operator & to types Text and Date. Details: Operator=& Left=exec [SP_ReportModel_Policy_Summary_Base_Template_AA_RA_Parm] 'Status''Frequency',' Right=12/7/2017 Also it gave me error without comma let bDate = BusinessDate, Source = Sql.Database("servername", "dbname", [Query="exec [SP_GetReport] 'Status','All','Frequency','"&bDate&"'"]) in Source

Helpful resources

Announcements
Coming Soon: T-Shirt Design Contest

Coming Soon: T-Shirt Design Contest

Keep your eyes open for our upcoming T-shirt design contest!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power BI Desktop Update - February 2020

Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors
Top Kudoed Authors