Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL command mode - unable to run command

I just answered this question but never tried to run it. So I tried it.. SQL command mode SQL SERVER - unable to Print

and I thought if Print works then the command will run for sure but to my surprise it didn't

    USE [DBName]  
        :setvar ScriptPath 'C:\Work\'
        :setvar SQLFile 'Test.sql'

         ----- commented  PRINT $(ScriptPath) + $(SQLFile)    ---- Works 
        GO
         :r $(ScriptPath) + $(SQLFile)   ---  Doesn't work 
-- throws:A fatal scripting error occurred. Incorrect syntax was encountered while parsing :r

             :r $(ScriptPath)+$(SQLFile)   ---  Doesn't work 
    -- throws:A fatal scripting error occurred. Unable to process :r command
             GO

I searched but couldn't find correct answer.

What is needed to be fixed here ?

like image 323
Akshay Avatar asked Dec 31 '25 14:12

Akshay


1 Answers

this worked.

USE [DBName]  
        :setvar ScriptPath "C:\Work\"
        :setvar SQLFile "Test.sql"

        GO
         :r $(ScriptPath)$(SQLFile)
like image 167
Akshay Avatar answered Jan 03 '26 10:01

Akshay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!