How to create new line when writing from table to txt file

  • Hi!

    I have big problem. I want to write into txt file data from table. With this "method"

    WHILE @@FETCH_STATUS = 0

    BEGIN

    EXEC @rc = sp_OAMethod @FileNameID, 'Write', Null , @VsebZapis

    IF @rc <> 0 BEGIN PRINT 'Error: Writing string data to file' ENDs

    and so on... and it works for one record in Table.

    But if I have more records txt file is not strucured like table.

    I want to have each record in table in one line in txt file.

    thanks

  • I'm assuming the variable @VsebZapis is the string you are writing?

    are you adding a CrLf to the end of it, so each record is on a single line in the file?

    SET @VsebZapis = @VsebZapis + CHAR(13) + CHAR(10)

    alternatively, you can use the WriteLine command, instead of Write:

    EXEC @rc = sp_OAMethod @FileNameID, 'WriteLine', Null , @VsebZapis

    WHILE @@FETCH_STATUS = 0

    BEGIN

    SET @VsebZapis = @VsebZapis + CHAR(13) + CHAR(10)

    EXEC @rc = sp_OAMethod @FileNameID, 'Write', Null , @VsebZapis

    IF @rc <> 0 BEGIN PRINT 'Error: Writing string data to file' ENDs

    thanks[/quote]

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • It works thanks 😉

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply