Below is the sticking point of the Stored procedure. I dump my results of a pretty lengthy SP into a table (#tbl_ADPExport) and when I do a select all agianst this table it displays the results as I need them to. But as soon as I try to use sqlcmd to export the results the table I get this error:Msg 102, Level 15, State 1, Procedure usp_PayRollTotalsExport, Line 156Incorrect syntax near 'sqlcmd'. Below is the Code I ma using in the SP what am I missing?CREATE TABLE #tbl_ADPExport( [Co Code] Varchar(50), [Batch ID] Varchar(50), [File #] Varchar(50), [Pay #] Varchar(50), [Job Cost#] Varchar(50), [Tax Frequency] Varchar(50), [Special Action] Varchar(50), TempDept varchar(50), [Rate Code] Varchar(50), Shift Varchar(50), [Temp Rate] Varchar(50), [Reg Hours] Varchar(50), [O/T Hours] Varchar(50), [PTO Code] Varchar(50), [PTO Hours] Varchar(50), [HOL Code] Varchar(50), [HOL Hours] Varchar(50), [JD Code] Varchar(50), [JD Hours] Varchar(50))INSERT INTO #tbl_ADPExport ([Co Code], [Batch ID], [File #], [Pay #], [Job Cost#], [Tax Frequency], [Special Action], TempDept, [Rate Code], Shift, [Temp Rate], [Reg Hours], [O/T Hours], [PTO Code],[PTO Hours], [HOL Code], [HOL Hours],[JD Code], [JD Hours])SELECT DISTINCT N'UR6' As [Co Code], N'EPIP300' As [Batch ID], #tbl_WORKEDPayRoll.EmployeeID As [File #], N'' As [Pay #], N'' As [Job Cost#], N'' AS [Tax Frequency], N'' As [Special Action], #tbl_WORKEDPayRoll.TempDept, N'' As [Rate Code], N'' As Shift, N'' As [Temp Rate], CASE WHEN SUM(#tbl_WORKEDPayRoll.Worked)>40.0 THEN 40.0 ELSE SUM(#tbl_WORKEDPayRoll.Worked) END AS [Reg Hours], CASE WHEN SUM(#tbl_WORKEDPayRoll.Worked)<=40.0 THEN 0 ELSE SUM(#tbl_WORKEDPayRoll.Worked)- 40.0 END As [O/T Hours], ISNULL(CASE WHEN #tbl_PTOPayRoll.Worked>0 THEN N'PTO' ELSE Null END, N'') As [PTO Code], CASE WHEN #tbl_PTOPayRoll.Worked IS NULL THEN 0 ELSE SUM(#tbl_PTOPayRoll.Worked) END AS [PTO Hours], ISNULL(CASE WHEN #tbl_HOLPayRoll.Worked>0 THEN N'HOL' ELSE NULL END, N'') As [HOL Code], ISNULL(CASE WHEN #tbl_HOLPayRoll.Worked>0 THEN #tbl_HOLPayRoll.Worked ELSE 0 END, 0) AS [HOL Hours], ISNULL(CASE WHEN #tbl_JDPayRoll.Worked>0 THEN N'JD' ELSE NULL END, N'') As [JD Code], ISNULL(CASE WHEN #tbl_JDPayRoll.Worked>0 THEN #tbl_JDPayRoll.Worked ELSE 0 END, 0) AS [JD Hours]FROM #tbl_HOLPayRoll RIGHT OUTER JOIN #tbl_PTOPayRoll RIGHT OUTER JOIN #tbl_WORKEDPayRoll ON #tbl_PTOPayRoll.EmployeeID = #tbl_WORKEDPayRoll.EmployeeID ON #tbl_HOLPayRoll.EmployeeID = #tbl_PTOPayRoll.EmployeeID LEFT OUTER JOIN #tbl_JDPayRoll ON #tbl_HOLPayRoll.EmployeeID = #tbl_JDPayRoll.EmployeeIDGROUP BY #tbl_WORKEDPayRoll.EmployeeID, #tbl_WORKEDPayRoll.TempDept, #tbl_WORKEDPayRoll.ActivityType, #tbl_PTOPayRoll.Worked, #tbl_HOLPayRoll.Worked, #tbl_JDPayRoll.Worked--SELECT * FROM #tbl_ADPExportsqlcmd -S . -d dbo.testdb -U someusername -P somepassword -s, -W -Q "Select * FROM #tbl_ADPExport" > \\servername\SharePathRoot\subfolder\ADPExport.csv