Hi I am using the below query to fetch some data :- then took it in sp and called the SP inside a batch file to export it in CSV file :- but the columns are having extra white spaces. which needs to be removed. how to do that-
Query :-
select replace(quotename(b.Store_Code,'"'),'','') as [Store Code],b.name as [Store Name],
quotename(c.TRANSNUM,'"') as [Transaction Number],
quotename(d.PRODUCT_SCANNED,'"') as [Lot Number],
quotename(p.product_code,'"') as [Product Code],
cast(d.QTY as numeric(9)) as [Quantity],
quotename(cast(d.Price_Sold as numeric(9,2)),'"') as [Price Per Unit],
quotename(cast(d.QTY*d.Price_Sold as numeric(9,2)),'"')as [Total Price],
quotename(convert(Varchar(25),d.TS_ID,121),'"') as [TS_ID],
c.TRANSDATE as transdate,
quotename(convert(varchar(25),d.PostingDate,121),'"') as [Posting Date]
from out_transactions (nolock) a
inner join store b on a.key1=b.store_code_id
inner join retail_transaction (nolock) c on a.key1=c.store_code_id and a.key2=c.TRANSTYPE
and a.key3=c.Cais and a.key4=c.TRANSNUM and a.key5=c.session_number
inner join dt_product (nolock) d on a.key1=d.store_code_id
and a.key2=d.TRANSTYPE and a.key3=d.Cais and a.key4=d.TRANSNUM
inner join product p on p.product_id=d.product_id
where a.sended <> 'D' and c.PROGRAMNAME <> 'inbound sales' and a.ts_id < CONVERT(Char(10),GETDATE(),126)
My Batch Script :--
SQLCMD -U <> -P <> -S%SERVER% -d<db name=""> -s, -Q "MissingSales" | findstr /V /C:"-" /B > %RootDir%\MissingSales_%date:~4,2%_%date:~7,2%_%date:~10,4%.csv
echo Store procedure processed successfully >> %LOG_FILE%
Please help me to remove the spaces from the exported CSV File. Thanks in Advance