SQL Server SQLCMD fails on INSERT with "Syntax error at line xxxxx near command '&'"

igetnqfo  于 2023-08-02  发布在  其他
关注(0)|答案(1)|浏览(97)

I use SQLCMD to import DDL generated by mssql-scripter and i got this error:

The offending INSERT is the following:
INSERT [dbo].[Settings_ContentPartFieldDefinitionRecord] ([Id], [Name], [Settings], [ContentFieldDefinitionRecord_id], [ContentPartDefinitionRecord_Id]) VALUES (12, N'JavascripttoRun', N'<settings DisplayName="Javascript to Run" InsertStuffFieldSettings.RawHtml=" $(document).ready(function() { ShowAdvancedLinkSettings(); }); $("#AdvancedLink_LinkType_Value").change(function() { ShowAdvancedLinkSettings(); }); function ShowAdvancedLinkSettings() { switch($("#AdvancedLink_LinkType_Value").val()) { case "External": $(".content-picker-field[data-field-name=''InternalContent'']").hide() $("#AdvancedLink_Caption_Text").parent().hide(); $("#AdvancedLink_ExternalUrl_Value").parent().parent().show(); $("#AdvancedLink_UrlBancaDati_Value").parent().parent().hide(); break; case "Internal": $("#AdvancedLink_ExternalUrl_Value").parent().parent().hide(); $(".content-picker-field[data-field-name=''InternalContent'']").show() $("#AdvancedLink_Caption_Text").parent().show(); $("#AdvancedLink_UrlBancaDati_Value").parent().parent().hide(); break; case "Banca dati": $("#AdvancedLink_ExternalUrl_Value").parent().parent().hide(); $(".content-picker-field[data-field-name=''InternalContent'']").hide() $("#AdvancedLink_Caption_Text").parent().hide(); $("#AdvancedLink_UrlBancaDati_Value").parent().parent().show(); break; default: $("#AdvancedLink_ExternalUrl_Value").parent().parent().hide(); $(".content-picker-field[data-field-name=''InternalContent'']").hide() $("#AdvancedLink_Caption_Text").parent().hide(); $("#AdvancedLink_UrlBancaDati_Value").parent().parent().hide(); break; } } " InsertStuffFieldSettings.OnFooter="true" />', 7, 51)

The INSERT is correct, if i run it with SSMS or Azure Data Studio it works.

I found on internet various articles with similar error messages but no solutions that worked for me.

Any ideas?

6qfn3psc

6qfn3psc1#

It come out that SQLCMD has a mechanism of variables with the format $(variable_name) that can be replaced at run time .

My data are not meant to be such variables, with the effect of fooling the mechanism and cause the error.

The solution is to use the -x option which suppresses the variable substitution mechanism (for reference see https://learn.microsoft.com/it-it/sql/tools/sqlcmd/sqlcmd-utility?view=sql-server-ver16 ).

相关问题