Txt File Print in SQL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ddtpmyra
    Contributor
    • Jun 2008
    • 333

    Txt File Print in SQL

    I wanted to have a job schedule inside MS SQL 2008 server that will print the txt file exported. Can this be done? What will be a syntax, sorry I don't know where to start to.
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Create an app that will handle the printing, create the job to export, call the printing app inside the job....

    Happy Coding!!!


    ~~ CK

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      SSIS allows you to use .Net programming. So conceivably, you could write a function to print the file. And call run the package when you want to do so.

      Comment

      • ddtpmyra
        Contributor
        • Jun 2008
        • 333

        #4
        I already exported my query result to a text file. My problem is how to make the auto printing. Can you give me sample to read? I never use ssis.

        Ty

        Comment

        • Rabbit
          Recognized Expert MVP
          • Jan 2007
          • 12517

          #5
          I don't know the code, I've never had to do that. I'm just saying it's conceivable you can do so because I know you can print a file using .Net if you so wished. I'm sure there's plenty of sample code showing how to print a file in .Net.

          Comment

          • ddtpmyra
            Contributor
            • Jun 2008
            • 333

            #6
            Thank you Rabbit.
            To make it work I created a procedure that will extract the data into text file and I created this scheduled batch file to print the file.

            Now, my next problem is how to tell inside my sql extract to file procedure to print it in new page for each record. See my code below. I use the combination of CHAR(13) + CHAR(10)
            to go to the next line. What about page break or new page? Is there an ascii code that will tell to go to the next page?

            Code:
            DECLARE @NewLineChar AS CHAR(2) = CHAR(13) + CHAR(10)
            
            SELECT   
            'DATE:'+getdate()+  @NewLineChar
            +'Customer Name:'+last_name+', '+first_name + NewLineChar
            +'Customer Record Number:'+rec_nbr +  @NewLineChar
            FROM 	Tbl_customer

            Comment

            • Rabbit
              Recognized Expert MVP
              • Jan 2007
              • 12517

              #7
              There is no ASCII code for a page break. You could try creating a new file for each record instead.

              Comment

              • ddtpmyra
                Contributor
                • Jun 2008
                • 333

                #8
                Thank you Rabbit I appreciate your inputs.

                Comment

                Working...