Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Shiva799
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
v-ljerr-msft
Employee
Employee

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

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.