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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
bmurf
Frequent Visitor

Native Query error writing to SQL

Short version:

This M statement:

let
Source = Sql.Database("AAA.database.windows.net", "CoolSQL"),
INSERT = Value.NativeQuery(Source, #"csv-import")
in
INSERT

 

receives this SYNTAX error:

DataSource.Error: Microsoft SQL: Incorrect syntax near the keyword 'On'.
Details:
DataSourceKind=SQL
DataSourcePath=AAA.database.windows.net;CoolSQL
Message=Incorrect syntax near the keyword 'On'.
ErrorCode=-2146232060
Number=156
Class=15

 

The advanced editor reports no syntax errors, it occurs during runtime when connecting to Azure SQL server.

Thanks for the help!

LONG VERSION (w code):

1) I'm pulling a CSV from sharepoint and transforming the data (basic transaction info - Trans ID, Batch ID, User ID, Date, Amount)

2) After cleaning data, Query #1 adds a custom column to generate a SQL query that checks to see the Batch ID already exists in SQL Table, if not add record.

 

= "IF EXISTS (SELECT * FROM [TABLE1] WHERE transaction_id = '" & Text.From([transaction_id]) & "')
SELECT * FROM [TABLE1]

ELSE INSERT INTO [dbo].[TABLE1]
(
[transaction_id],
[gno_org_id],
[gno_software_id],
[person_comp_id],
[received_at],
[fund],
[amount]
)

VALUES('"
& Text.From([transaction_id]) & "',"
& Text.From([gno_org_id]) & ","
& Text.From([gno_software_id]) & ","
& Text.From([person_comp_id]) & ","
& Text.From([received_at]) & ","
& Text.From([fund]) & ","
& Text.From([amount]) & ","
& ")
SELECT * From [dbo].[TABLE1]"

 

NOTE: Everything to here works fine - verified Query #1 runs in SSMS

3) Query #2 connects to SQL: 

let
Source = Sql.Database("AAA.database.windows.net", "CoolSQL"),
INSERT = Value.NativeQuery(Source, #"csv-import")
in
INSERT

 

but receives this SYNTAX error:

 

DataSource.Error: Microsoft SQL: Incorrect syntax near the keyword 'On'.
Details:
DataSourceKind=SQL
DataSourcePath=AAA.database.windows.net;CoolSQL
Message=Incorrect syntax near the keyword 'On'.
ErrorCode=-2146232060
Number=156
Class=15

 

 

1 REPLY 1
lbendlin
Super User
Super User

Do you have access to the SQL server query log? "on"  would assume that somewhere someone is trying to do a join.

 

Also, your approach "Insert unless already exists" can be done in a couple other ways, with less effort.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.