Difference between revisions of "Example of executing sql script by sqlcmd"

From MyWiki
Jump to: navigation, search
(Created page with "< source lang="sql"> USE AdventureWorks2012; GO SELECT p.FirstName + ' ' + p.LastName AS 'Employee Name', a.AddressLine1, a.AddressLine2 , a.City, a.PostalCode FROM P...")
 
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
< source lang="sql">
+
<source lang="sql">
 
USE AdventureWorks2012;   
 
USE AdventureWorks2012;   
 
GO   
 
GO   
Line 15: Line 15:
  
 
</source>
 
</source>
 +
sqlcmd -S myServer\instanceName -i C:\myScript.sql<br>
 +
Or to output to a text file <br>
 +
sqlcmd -S myServer\instanceName -i C:\myScript.sql -o C:\EmpAdds.txt<br>

Latest revision as of 13:15, 15 March 2017

USE AdventureWorks2012;  
GO  
SELECT p.FirstName + ' ' + p.LastName AS 'Employee Name',  
a.AddressLine1, a.AddressLine2 , a.City, a.PostalCode   
FROM Person.Person AS p   
   INNER JOIN HumanResources.Employee AS e   
        ON p.BusinessEntityID = e.BusinessEntityID  
    INNER JOIN Person.BusinessEntityAddress bea   
        ON bea.BusinessEntityID = e.BusinessEntityID  
    INNER JOIN Person.Address AS a   
        ON a.AddressID = bea.AddressID;  
GO

sqlcmd -S myServer\instanceName -i C:\myScript.sql
Or to output to a text file
sqlcmd -S myServer\instanceName -i C:\myScript.sql -o C:\EmpAdds.txt