سؤال

hk=conn:query({live=true,sql ="select DISTINCT O.OrderId, (SELECT R.ReportBody + CHAR(13)+ CHAR(10) +'Modified By: ' + UM.FirstName + ' at ' + UM.LastName + ' CRLF ' +'Authored By: ' + UC.FirstName + ' at ' + UC.LastName + ' CRLF ' + 'CRLF' AS [text()] FROM dbo.OrderReports R INNER JOIN dbo.Users UM ON R.ModifiedById = UM.UserId INNER JOIN dbo.Users UC ON R.CreatedById = UC.UserId WHERE R.OrderId = O.OrderId ORDER BY R.CreateDate FOR XML PATH('')) 'OrderReport'FROM dbo.Orders O "})

Now, its printing CRLF instead of giving A LINE BREAK,I can't use char(13) either, not working. How can I get this fixed ?

هل كانت مفيدة؟

المحلول

Just replace +'CRLF' with +CHAR(13)+CHAR(10) (there are some +' CRLF ' which I suppose should be treated like +'CRLF')

Anyway, CR LF (carriage return followed by linefeed, char(13)+char(10)) is the DOS-like line terminator, the Unix-like one is LF (char(10))

Could it be that the output of your query should be JSON-compatible? In this case, you should replace +'CRLF' (and +' CRLF ') with +'\n' or +'\\n' (or even +'\\\\n', depending on the number of levels that use \ as the escape character).

If, instead, as it seems from your comments, you are in a Unixish environment (lua in Iguana) that gets control characters escaped from SQL, you will have to live with that, by replacing +'CRLF' with +CHAR(10) and letting the interpretation of the resulting \ns happen at a later stage.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top