DECLARE @query NVARCHAR(2000)
SELECT @query = 'osql -n -w 5000 -E -s "," -d master -Q "
SELECT
a.HospitalName,
a.HospitalCode,
c.ProductName,
b.UnitsDiscarded,
b.DateEntered,
b.DateCompleted,
b.CompiledBy
FROM
Ivana_test.dbo.Units b
INNER JOIN Hospitals a ON (a.HospitalID = b.HospitalID)
INNER JOIN Products c ON (b.ProductID = c.ProductID)
INNER JOIN FateOfProducts d ON (d.FateID = b.FateID)
ORDER BY
a.HospitalID" -o "c:\test.txt"'
EXEC Ivana_test.dbo.xp_cmdshell @query
I am trying to run this query that will hopefully create me comma delimited results in a file,but this file never gets created. It runs and saying 1 row affected but no file there, could somebody have a look at it please
SELECT @query = 'osql -n -w 5000 -E -s "," -d master -Q "
SELECT
a.HospitalName,
a.HospitalCode,
c.ProductName,
b.UnitsDiscarded,
b.DateEntered,
b.DateCompleted,
b.CompiledBy
FROM
Ivana_test.dbo.Units b
INNER JOIN Hospitals a ON (a.HospitalID = b.HospitalID)
INNER JOIN Products c ON (b.ProductID = c.ProductID)
INNER JOIN FateOfProducts d ON (d.FateID = b.FateID)
ORDER BY
a.HospitalID" -o "c:\test.txt"'
EXEC Ivana_test.dbo.xp_cmdshell @query
I am trying to run this query that will hopefully create me comma delimited results in a file,but this file never gets created. It runs and saying 1 row affected but no file there, could somebody have a look at it please