-4

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

enter image description here

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="<script type="text/javascript"> $(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; } } </script> " 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?

lfassio
  • 23
  • 4
  • 2
    [Please do not upload images of code/data/errors when asking a question.](//meta.stackoverflow.com/q/285551) – Thom A Jul 04 '23 at 15:05
  • 5
    That error and the `INSERT` statement don't appear to be related; there is no `&` in that query. – Thom A Jul 04 '23 at 15:09
  • You ran SQLCMD from CMD. & is mostly equivalent to ; (end of command) in most programming languages. Try running from PowerShell. Or better yet, use either Invoke-SqlCmd in SQLPS or Invoke-DbaQuery from DBATOOLS. – PollusB Jul 05 '23 at 15:53

1 Answers1

1

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).

lfassio
  • 23
  • 4