I’m a bit surprised that I can’t find a quick solution to what I’m up against, seems like it’d be a common thing to deal with. I can’t get rid of the trailing spaces in my select query. I’d like to get the data into a csv file. I’m happy to copy/ paste the results from SSMS “results to text” if that’s easier. Either way, my query is:
declare @maxDate date = (select MAX(TradeDate) from tblDailyPricingAndVol)
select p.Symbol, ','
from tblDailyPricingAndVol p
where p.Volume > 1000000 and p.Clse <= 40 and p.TradeDate = @maxDate
order by p.Symbol
and it returns:
A ,
AA ,
ABB ,
etc. Rtrim around the p.Symbol field didn’t help. If I could figure out the best solution, I’d have results of:
A,AA,ABB
and so on. Any takers? Thanks in advance as always..
From your expected result, it seems that you want to concatenate the
symbolvalue from all the rows into one comma demimited string.In order to do that, you can do this :-
Additional alternate methods can also be referenced here
Regarding your issue with the
RTRIMnot working, that seems very odd. To be on the safe side, i have addedLTRIM + RTRIMto the above query. However, as long as yoursymbolcolumn is some kind ofvarchar, there is really no reason for theRTRIMto not work.Can you clarify the datatype of
symbolcolumn in your table?