Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Express Edition and Compact Edition (2005)
 Problem running script file

Author  Topic 

SilentCodingOne
Starting Member

20 Posts

Posted - 2008-12-21 : 23:31:16
I'm working on a homework problem where I need to create a script file that will be run from SQLCMD. The script needs to query the Northwind database and based on the company passed to it from the SQLCMD line produce an output file containing a list of the employees who have sold to that company. Whenever I run it I get the following error message:

Msg 126, Level 15, State 1, Server BILL-PC, Line 5
Invalid pseudocolumn "$companyName".

Here is the SQLCMD like:

sqlcmd -i C:\query4.sql -v companyName=Island Trading -o C:\output.txt

Here is the code in my script file:

USE Northwind

SELECT DISTINCT FirstName, LastName FROM dbo.Employees
INNER JOIN dbo.Orders ON Employees.EmployeeID = Orders.EmployeeID
WHERE Orders.CustomerID = (SELECT CustomerID FROM Customers WHERE CompanyName = ($companyName))

Any help would be appreciated

Thanks

SilentCodingOne
Starting Member

20 Posts

Posted - 2008-12-22 : 23:09:56
For anyone else who may run into a similar issue the problem was wth how I worded Island Trading in the sqlcmd. The following is the correct syntax:


sqlcmd -i C:\query4.sql -v companyName = "'Island Trading'" -o C:\output.txt
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-12-23 : 00:31:28
Thank you for taking the time to update your thread with the solution. Hopefully it'll help someone else down the road with a similar problem.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -