none
Printing data from SQL tables

    Question


  • I am programming with SQL and i would like to know how do I print information from the tables to my printer.
    Thanks in advance
    Friday, August 24, 2007 3:26 PM

Answers

  • If you just want to print them out "ugly", you can easily use SQLCMD to stream the output to a text file and print that (you might even be able still to stream the output of a DOS command to the lpt1 device and print the output to a printer.

     

    But if you want to print them pretty, you could use EXCEL's data features (in 2007, it is the data bar, choose the From Other Sources; SQL Server) and just have it automatically refresh the data.  You would not need to cut and paste...

     

    Or you could use Reporting Services, like I mentioned before.

    Tuesday, August 28, 2007 1:37 AM
    Moderator
  • That's Louis' suggestion.  I hope this link might help:

     

    http://msdn2.microsoft.com/en-us/library/ms170207.aspx

     

    Dan

     

    Tuesday, August 28, 2007 7:47 PM

All replies

  • any reporting tool at hand?

     

     

    AMB

    Friday, August 24, 2007 3:39 PM
    Moderator
  • Huh? What reporting tool? I have no idea how to do it. I have tables with different thing, ex. Names, ID Numbers etc. I want to be able to print the names for example.
    Friday, August 24, 2007 3:41 PM
  • Would this have anything to do with Crystal Reports? I am not sure how crystal reports work.
    Friday, August 24, 2007 4:59 PM
  • You could run the query in SSMS (SQL Server 2005) or Query Analyzer (SQL Server 2000) and direct the output to a file.

     

    You can then print the file (by importing it into Word, Excel, etc., and then using the print features of these products).

     

    If you don't need column headers, you can use "Ctrl-A" (select all) in SSMS or QA to grab the entire data content of the grid, and then use Ctrl-V to paste the data into Excel.  This should work as long as you don't exceed the limits of Excel, which are much smaller than SSMS.  (For example, SSMS lets you have over 4,000 columns in a query output, but Excel only allows 256; and you can have millions of rows in a query output, but Excel's limit is around 65,000.)  Once the data are in Excel, you can use all of Excel's print features.

     

    HTH.

     

    Dan

    Saturday, August 25, 2007 3:51 AM
  • Do you just want to do this once, just for testing?  Or are you looking for something more elegant and repeatable?

     

    SQL Server comes with reporting services, which you can use to build reports.  But there are other methods, using excel's built in data facilities, SQLCMD, managment studio, crystal reports etc. But it is completely dependent on what your goal is.

    Saturday, August 25, 2007 5:13 AM
    Moderator
  • I have a customer database which includes transactions. At each shift I want to print out the transactions for the previous shift. I don't want to copy and paste in excel.
    Monday, August 27, 2007 1:05 PM
  • Perhaps, then, you could have a scheduled SSIS task (presuming you are using SQL Server 2005; otherwise a DTS task) that exports the data to a file, and then perhaps a task to read the data into Word, Wordpad, Notepad, etc., and then print them from such a program.

     

    Will that work for you?

     

    Unless you have a very simple printer, I think you will need something that converts the text to the data stream that modern printers seem to expect.  I am not sure that many modern printers will readily print ASCII characters that come their way, without any sort of setup characters to precede them.

     

    Dan

     

    Monday, August 27, 2007 10:42 PM
  • If you just want to print them out "ugly", you can easily use SQLCMD to stream the output to a text file and print that (you might even be able still to stream the output of a DOS command to the lpt1 device and print the output to a printer.

     

    But if you want to print them pretty, you could use EXCEL's data features (in 2007, it is the data bar, choose the From Other Sources; SQL Server) and just have it automatically refresh the data.  You would not need to cut and paste...

     

    Or you could use Reporting Services, like I mentioned before.

    Tuesday, August 28, 2007 1:37 AM
    Moderator
  • Louis,

     

    I am not very familiar with Reporting Services.  Can it be instructed to print automatically the output from a query?

     

    Dan

    Tuesday, August 28, 2007 1:56 AM
  •  

    To print query Table results

    1. Select the columns or rows that you want to print.

    2. Use the Copy command to move them to the Clipboard.

    3. Switch to the Windows program you want to use to print the results.

    4. Use the Paste command to move the query results from the Clipboard.

    5. Format and print the results.

    Databasetimes.net

    FAIZ, MCDBA
    Tuesday, August 28, 2007 4:03 PM
  • Do you have any idea how to use the SQLCMD to stream the output to a text file? Any information would really help. Thanks.
    Tuesday, August 28, 2007 5:08 PM
  • That's Louis' suggestion.  I hope this link might help:

     

    http://msdn2.microsoft.com/en-us/library/ms170207.aspx

     

    Dan

     

    Tuesday, August 28, 2007 7:47 PM
  • I have no idea if RS can do that (I avoid that stuff like the plague) 

     

    That would be a question for the RS forum, if SQLCMD won't do what you want Smile

    Tuesday, September 04, 2007 3:27 AM
    Moderator