Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sql server rtrim not working for me, suggestions?

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..

like image 349
StatsViaCsh Avatar asked Dec 27 '25 16:12

StatsViaCsh


1 Answers

p.Symbol is defined as CHAR(8), and CHAR values cannot be trimmed. Convert to N/VARCHAR(8) before trimming.

like image 172
devio Avatar answered Dec 30 '25 08:12

devio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!