Question : CR not inserted in text file created from SQL Server

Hi,

I create a file from a StoredProc using the file scripting object. The file creation is OK but the CR between each lines is not inserted correctly.

T-SQL instruction to create the string:
SET @Msg = @Msg +   @Lot + '|' + @barcode + '|' + @cnt + '|' + LTRIM(STR(@qty)) + '|' + LTRIM(STR(@PoidsNet))  + CHAR(13)

A PRINT from the SP gives me something like:
0106002387002|145238|TOT-VN-BLEUF|29|246
0106002735002|1456325986523|BXP-RP-ROM|30|-217

which is fine. But the file looks like:
0106002387002|145238|TOT-VN-BLEUF|29|246{CR}0106002735002|1456325986523|BXP-RP-ROM|30|-217{CR}

T-SQL to write the string is:
execute @hr = sp_OAMethod  @objTextStream, 'Write', Null, @String

the {CR} represent the CHAR(13) caracter (the little square) which does not copy-pasted from the file. In reality, instead of the {CR}, there is a little square, when opening the file in notepad.

Anyone have an idea how to fix this? This file must have a CR because it is imported by another tier-party system.

thanks a lot for your help

Answer : CR not inserted in text file created from SQL Server

I believe you should use a combination of chr(10) and chr(13)

...LTRIM(STR(@PoidsNet))  + CHAR(13) + CHR(10)

or

...LTRIM(STR(@PoidsNet))  + CHAR(10) + CHR(13)

Random Solutions  
 
programming4us programming4us