Hi all, I have written a simple Query to Query Birthdates for a given month. All of that works great. i would like to be able to output the given results to a CSV file. So this is 2 parts. I have been able to execute the Query successfully for the results i want, but i cant put stage 2 (Outputting a CSV file) together, although i am able to do these seperatley to some extent. I have created a view of just the data that I wanted, but when I am aonly able to output ALL of the data in that view, I am unsuccessful in outputing based on my Query. Below is the Query also I have listed the code that I am using to output the CSV, it doesnt matter how I change it it failes other than *.
EXEC master..xp_cmdshell 'sqlcmd -S pmdb01 -d Ntier_Training -Q "SELECT * FROM dbo.Birthdate" -o "C:\output1.csv"'
DECLARE @MonthNumber int
SET @MonthNumber = 12
SELECT Prim_Policy_Certificate_No, Patient_Name, Patient_Street1, Patient_Street2, Patient_City, Patient_State, Patient_Zip_Code,
WHERE MONTH(Patient_DOB) = @MonthNumber