I am trying to run the following bcp union query. I have two queries on two tables that I am trying to join the output for. Individually they work but it doesn't like the UNION command. Any Ideas would be helpful
@bcp "select 'SL613' ,rtrim(posting_code),ltrim(rtrim(cast(cast(sum(journal_amount) as money) as char(20)))),rtrim(nlyear),'1' from SL613.scheme.nltranm WHERE nlyear = '07' and (trans_period < '02' or trans_period = 'O') group by posting_code,nlyear having sum(journal_amount) >= 0.01 or sum(journal_amount) <= -0.01 order by posting_code UNION select 'SL614' ,rtrim(posting_code),ltrim(rtrim(cast(cast(sum(journal_amount) as money) as char(20)))),rtrim(nlyear),'1' from SL614.scheme.nltranm WHERE nlyear = '07' and (trans_period < '02' or trans_period = 'O') group by posting_code,nlyear having sum(journal_amount) >= 0.01 or sum(journal_amount) <= -0.01 order by posting_code" queryout "S:\MANAGERS\Group Consolidation\2007 Consolidation\Batch Files\Jan\SLRL.txt" -S SVHOSAGE -T -t "," -r \n -c
Thanks
Pete
@bcp "select 'SL613' ,rtrim(posting_code),ltrim(rtrim(cast(cast(sum(journal_amount) as money) as char(20)))),rtrim(nlyear),'1' from SL613.scheme.nltranm WHERE nlyear = '07' and (trans_period < '02' or trans_period = 'O') group by posting_code,nlyear having sum(journal_amount) >= 0.01 or sum(journal_amount) <= -0.01 order by posting_code UNION select 'SL614' ,rtrim(posting_code),ltrim(rtrim(cast(cast(sum(journal_amount) as money) as char(20)))),rtrim(nlyear),'1' from SL614.scheme.nltranm WHERE nlyear = '07' and (trans_period < '02' or trans_period = 'O') group by posting_code,nlyear having sum(journal_amount) >= 0.01 or sum(journal_amount) <= -0.01 order by posting_code" queryout "S:\MANAGERS\Group Consolidation\2007 Consolidation\Batch Files\Jan\SLRL.txt" -S SVHOSAGE -T -t "," -r \n -c
Thanks
Pete