I understand that this has been asked many times and this is the syntax i use
EXECUTE master.dbo.Xp_cmdshell 'bcp "select 'I_CLM_ID', 'I_CHARGES' union all SELECT top 100 cast(I_CLM_ID as varchar(25)), cast(I_CHARGES as varchar(10)) FROM BRS_ANALYZE_MILLION.dbo.APC_ANALYZE_LINE_PRICED_150k_2" queryout "F:\projects\0113_Jan14\OUTPUT\Test.txt" -t"|" -c -T'
i get an error Incorrect syntax near 'I_CLM_ID'.
i run the select statement within the double quotes and it gives the result query with 101 records but when i run everything from bcp to the last -T it gives me another error
Msg 103, Level 15, State 4, Line 1
The identifier that starts with 'select 'I_CLM_ID', 'I_CHARGES' union all SELECT top 100 cast(I_CLM_ID as varchar(25)), cast(I_CHARGES as varchar(10)) FROM BR' is too long. Maximum length is 128. Msg 102, Level 15, State 1, Line 4 Incorrect syntax near 'queryout'.
what am i doing wrong
i know to do SSIS Import/Export Wizard but wanted to do i through Bcp