Just an interesting find I wanted to share. When I create my cursor with traditional c(N) widths, the CSV export does NOT have any extra spaces added to the output.
pseudoid,zip3,prov03,prov03other,prov06,prov07,prov07other,prov08 "Pseudo1","333","C001","","10","C021","","C025" "Pseudo2","333","C001","","20","C021","","C026" "Pseudo3","333","C001","","30","C021","","C019"
But when I use varchar v(N) field declarations, it appends spaces to the end of the field values:
pseudoid,zip3,prov03,prov03other,prov06,prov07,prov07other,prov08 "Pseudo1 ","333","C001","
","10 ","C021","
","C025" "Pseudo2 ","333","C001","
","20 ","C021","
","C026" "Pseudo3 ","333","C001","
","30 ","C021","
","C019"
Here's the declaration:
CREATE CURSOR curProvData (iid i, PseudoID c(20), Zip3 c(3), Prov03 c(4), Prov03Other c(254), Prov06 c(8), Prov07 c(4), Prov07Other c(254), Prov08 c(4))
if you want to avoid the extra spaces at the end trim() and or alltrim() is your friend.
Koen
2017-11-27 17:43 GMT+01:00 mbsoftwaresolutions@mbsoftwaresolutions.com:
Just an interesting find I wanted to share. When I create my cursor with traditional c(N) widths, the CSV export does NOT have any extra spaces added to the output.
pseudoid,zip3,prov03,prov03other,prov06,prov07,prov07other,prov08 "Pseudo1","333","C001","","10","C021","","C025" "Pseudo2","333","C001","","20","C021","","C026" "Pseudo3","333","C001","","30","C021","","C019"
But when I use varchar v(N) field declarations, it appends spaces to the end of the field values:
pseudoid,zip3,prov03,prov03other,prov06,prov07,prov07other,prov08 "Pseudo1 ","333","C001","
","10","C021","
","C025""Pseudo2 ","333","C001","
","20","C021","
","C026""Pseudo3 ","333","C001","
","30","C021","
","C019"Here's the declaration:
CREATE CURSOR curProvData (iid i, PseudoID c(20), Zip3 c(3), Prov03 c(4), Prov03Other c(254), Prov06 c(8), Prov07 c(4), Prov07Other c(254), Prov08 c(4))
[excessive quoting removed by server]
On 2017-11-27 11:59, Koen Piller wrote:
if you want to avoid the extra spaces at the end trim() and or alltrim() is your friend.
Koen
Koen,
I think there's a misunderstanding. Please tell me how using a COPY TO MyCSVFile TYPE CSV can be manipulated with a TRIM or ALLTRIM? Are you saying I should devise some sort of construct like the pseudo-code following this to trim everything before the COPY TO ... TYPE CSV command?
FOR EACH Column in Table.Columns REPLACE Column with ALLTRIM(Column) in Table ALL ENDFOR
I doubt that's what you would do, so enlighten me please.
Thanks, --Mike
On Mon, Nov 27, 2017 at 1:10 PM, mbsoftwaresolutions@mbsoftwaresolutions.com wrote:
I think there's a misunderstanding. Please tell me how using a COPY TO MyCSVFile TYPE CSV can be manipulated with a TRIM or ALLTRIM?
You *COULD* do it with the FIELDS clause, IIRC, but it's much more understandable if you use SELECT ... INTO CURSOR to do the preprocessing, data manipulation, reordering, filtering, etc with a Rushmore-izable query, then do a COPY TO TYPE CSV with the result.
The *best* way is to not put the trailing spaces into the varchar fields to begin with :)
On Mon, 27 Nov 2017 11:43:00 -0500, mbsoftwaresolutions@mbsoftwaresolutions.com wrote:
But when I use varchar v(N) field declarations, it appends spaces to the end of the field values:
Hi Mike,
you can resolve in this way:
set fields GLOBAL set fields to
set fields to PseudoID = rtrim(PseudoID), Zip3, Prov03, Prov03Other = rtrim(Prov03Other), Prov06, Prov07, Prov07Other = rtrim(Prov07Other), Prov08
copy to MyCSVFile type CSV
set fields to set fields LOCAL
Be careful with the order of the various "set fields ..." commands!
Hi Mike,
to have that result you have put values in the vachar defined fields without trimming blanks, why?
Anyway you can resolve in this way:
set fields GLOBAL set fields to
set fields to PseudoID = rtrim(PseudoID), Zip3, Prov03, Prov03Other = rtrim(Prov03Other), Prov06, Prov07, Prov07Other = rtrim(Prov07Other), Prov08
copy to MyCSVFile type CSV
set fields to set fields LOCAL
Be careful with the order of the various "set fields ..." commands!
Gianni
On Mon, 27 Nov 2017 11:43:00 -0500, mbsoftwaresolutions@mbsoftwaresolutions.com wrote:
Just an interesting find I wanted to share. When I create my cursor with traditional c(N) widths, the CSV export does NOT have any extra spaces added to the output.
pseudoid,zip3,prov03,prov03other,prov06,prov07,prov07other,prov08 "Pseudo1","333","C001","","10","C021","","C025" "Pseudo2","333","C001","","20","C021","","C026" "Pseudo3","333","C001","","30","C021","","C019"
But when I use varchar v(N) field declarations, it appends spaces to the end of the field values:
pseudoid,zip3,prov03,prov03other,prov06,prov07,prov07other,prov08 "Pseudo1 ","333","C001"," ","10 ","C021"," ","C025" "Pseudo2 ","333","C001"," ","20 ","C021"," ","C026" "Pseudo3 ","333","C001"," ","30 ","C021"," ","C019"
Here's the declaration:
CREATE CURSOR curProvData (iid i, PseudoID c(20), Zip3 c(3), Prov03 c(4), Prov03Other c(254), Prov06 c(8), Prov07 c(4), Prov07Other c(254), Prov08 c(4))