none
sqlcmd -v parameter does not seem to be working on Linux RRS feed

  • Question

  • I've installed sqlcmd on a Linux server: 

     /opt/mssql-tools/bin/sqlcmd -?
    Microsoft (R) SQL Server Command Line Tool
    Version 17.4.0001.1 Linux
    Copyright (c) 2012 Microsoft. All rights reserved

    But the help does not display the -v (lower case) parameter that the microsoft docs indicate can be used to pass variables into a script.    

    When I call  

            sqlcmd -v ColumnName ="FirstName" -i c:\testscript.sql

    I get 

      Sqlcmd: 'ColumnName" "=FirstName': Invalid argument. Enter '-?' for help.

    Any ideas? I've tried all types of permutations.  
          -variable
           with / without quotes 
           escaping all of the different symbols...
           

    thanks for any help,

    jon

    Friday, October 4, 2019 5:06 PM

All replies

  • I had passed database name  in column name...I had check for windows server . do for  Linux based.


    https://social.technet.microsoft.com/wiki/contents/articles/37872.sql-server-installation-on-centos-linux.aspx

    Friday, October 4, 2019 8:38 PM
  • When I call  
            sqlcmd -v ColumnName ="FirstName" -i c:\testscript.sql

    Be aware that in Linux the way to identify drive and folder is different; the C:\ identification is not recognized.

    What GNU/Linux distribution are you using?

    Try

          $ ColumnName="FirstName"
          $ export ColumnName
          $ sqlcmd -i testscript.sql  

     
    Note: Variable Precedence (Low to High) 

    If a variable defined by using :Setvar and an environment variable have the same name, the variable defined by using :Setvar takes precedence.

     


    José Diz     Belo Horizonte, MG - Brasil     [query performance tuning: Porto SQL]


    Este conteúdo é fornecido sem garantias de qualquer tipo, seja expressa ou implícita.

    Sunday, October 6, 2019 7:16 PM
    Answerer
  • Hi JonJ Silver,

     

    >>sqlcmd -v ColumnName ="FirstName" -i c:\testscript.sql

     

    What version of Linux are you using, why do you have a C drive?

     

    Best regards,

    Dedmon Dai


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Monday, October 7, 2019 6:27 AM
  • Thanks for all of your responses - typo on the command line. Redhat Linux.  I copied the command from a ms document and tried to reference that document, but the forum would not allow me to paste the url. 

    I am on RedHat linux. 

    uname -a 

    Linux serverhostname 3.10.0-957.12.2.el7.x86_64 #1 SMP Fri Apr 19 21:09:07 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

    /opt/mssql-tools/bin/sqlcmd -v tranMas='aaa' -i x.sql
    Sqlcmd: 'tranMas=aaa': Invalid argument. Enter '-?' for help.


    Monday, October 7, 2019 3:36 PM
  • As you mentioned earlier, there is no -v option in the sqlcmd utility for linux.

    Try

          $ tranMas="aaa"
          $ export tranMas
          $ /opt/mssql-tools/bin/sqlcmd  -i x.sql

    or

          $ export tranMas="aaa"
          $ /opt/mssql-tools/bin/sqlcmd  -i x.sql


    José Diz     Belo Horizonte, MG - Brasil     [query performance tuning: Porto SQL]


    Este conteúdo é fornecido sem garantias de qualquer tipo, seja expressa ou implícita.

    Monday, October 7, 2019 3:54 PM
    Answerer
  • For Closure, 

    Don't like export. They stay around. 

    I just wrote my own text substitution.  Just a a one liner  sed  for each parm 

    Tuesday, October 8, 2019 7:56 PM
  • Hi JonJ Silver,

     

    Have you solved this problem ?  In order to close this thread, please kindly mark your replies as answers. By doing so, it will benefit all community members who are having this similar issue.  Your contribution is highly appreciated.

     

    Best regards,

    Dedmon Dai


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Wednesday, October 9, 2019 8:45 AM