SQLCMD utility lets us execute Transact-SQL statements, Stored procedures, and other script files at the command prompt,
In this post, let us see an example for invoking sql file through SQLCMD
I have saved the following T-SQL script in path D:\work\SQLQuery1.sql
Now goto Start -> Search Programs and files -> type CMD
Form SQLCMD command line like shown below:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcZwmF1F5LHkppzGkDOAT9igqAEk5bXxTGUx0g6Fp0WXGEVJ-ljvg-K6CxbBCL90VVmByBmdLuBxG9CukoCXtaW42QXc0G2zngETz5qh3t3ZK2yhNWECEDS0yPGaJXyfg0UoCQ4PKHSSAv/s640/cmd.JPG)
in SSMS Query Editor in SQLCMD mode,
in a Windows script file or
in an operating system (Cmd.exe) job step of a SQL Server Agent job.
In this post, let us see an example for invoking sql file through SQLCMD
I have saved the following T-SQL script in path D:\work\SQLQuery1.sql
USE $(database) GO SELECT ShiftID,Name FROM [HumanResources].[Shift]
Now goto Start -> Search Programs and files -> type CMD
Form SQLCMD command line like shown below:
sqlcmd -S ServerName -i C:\myScript.sql -U sa -P Password -v database="[Database Name]"
No comments:
Post a Comment