Showing results for 
Search instead for 
Did you mean: 
Helper III
Helper III

ODBC SQL incorrect syntax near '='



I am trying to run this SQL using ODBC connection in Power Query:


IIF(column1 = 'C', Left(column2,10), '') AS 'Column3'
FROM table



But keep getting the following error:

DataSource.Error: ODBC: ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Line 2: Incorrect syntax near '='.


What do I need to do to correct this?


Thank you in advance.



Community Support
Community Support

Hi @cfpvin ,

Based on my test, it could work in my side so the syntax seems correct.


Please try to change the table name as a whole table name path like database.tablename to check it or clear the permissions to try to reconnect to ODBC.


Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Super User II
Super User II

@cfpvin your sql syntext seems to be correct. You can test your sql code at below


if you have access to query browser of the DB, you may try running query there to check if it is working fine at DB end or not. 


IIF(table1.column1 = 'C', Left(table1.column2, 10), '') AS 'Column3'


Did I answer your question? Mark my post as a solution!
Appreciate your Kudos

Proud to be a Super User!

Follow me here

Solution Supplier
Solution Supplier

Hey @cfpvin 


Usually when I see this error it is due to the single quotes for the declaration try removing the single quotes on Column3.


You can also try adding double quotes, however if you do this in Power Query via Advanced Editor then you'll need double quotes x2 like  ""Column3"".

Did my answer(s) help you? Give it a kudos by clicking the Thumbs Up! ?
Did my post answer your question(s)? Mark my post as a solution. This will help others find the solution.
Resolver II
Resolver II



"," in the end of the statement could be the cause of error. Try this


IIF(column1 = 'C', Left(column2,10), '') AS 'Column3'
FROM table



Hi @alekhved ,


Thanks for the help. I removed the "," in the end and still get the same error.  The error shows for something with the "=".



Well in that case, what's the datatype of Column1?

@alekhvedThe datatype is text for Column1 

hi @cfpvin 


Try this. I believe the problem is not with "=", but the condition expression. Also I hope the datatype of Column2 is also varchar, else it could be problem too.


IIF(cast(column1 as varchar(10) = 'C', Left(column2,10), '') AS 'Column3'
FROM table



Helpful resources

PBI_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Get Ready for Power BI Dev Camp

Microsoft named a Leader in The Forrester Wave

Microsoft received the highest score of any vendor in both the strategy and current offering categories.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Top Kudoed Authors