Hello I am trying to use sqlcmd to run a set of sql statements. If I use -i switch and input a file with sql statements, it is working fine, but I am trying to use the sql statements using -q to avoid the creation of the input file. But I am not having luck with -q, can someone let me know if putting multiple lines of code is possible in -q switch like below? A simple restore command like below. If I use the whole restore command in single line it works fine like below: sqlcmd -E -S servername -d master -Q "restore database bestst_test from disk='E:Backup esteststestst_20101222.bak' with move 'BESMgmt415_data' to 'Erogram FilesMicrosoft SQL ServerMSSQL.1MSSQLDATAestst_test.mdf',move 'BESMgmt415_log' to 'Erogram FilesMicrosoft SQL ServerMSSQL.1MSSQLDATAestst_test_log.ldf'" but if I split the restore command into 3 lines like below, it fails, can someone let me know how to use the multiple line feature in sqlcmd -q switch? sqlcmd -E -S servername -d master -Q "restore database bestst_test from disk='E:Backup esteststestst_20101222.bak' with move 'BESMgmt415_data' to 'Erogram FilesMicrosoft SQL ServerMSSQL.1MSSQLDATAestst_test.mdf', move 'BESMgmt415_log' to 'Erogram FilesMicrosoft SQL ServerMSSQL.1MSSQLDATAestst_test_log.ldf'" Thanks Satya
I figured it out myself with the help of a friend. Spanning the same command across multiple lines is not possible, my main intention in asking this question was to see if 2 statements can be executed using just one -q switch like 'restore db1,restore db2' in one -q swith, turns out we can do it by separating them with semi-colon, but everything has got to be in one line like below: sqlcmd -E -S servername -d master -Q " restore db1;restoredb2;" Satya
Appreciate your workaround here too, in any case always best to refer the BOL documentation for such syntax or information: http://msdn.microsoft.com/en-us/library/ms165702.aspx http://msdn.microsoft.com/en-us/library/ms170207.aspx - tutorial