Print data through Store Procedure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hariharanmca
    Top Contributor
    • Dec 2006
    • 1977

    Print data through Store Procedure

    any know how to Print data through Store Procedure to the printer Directly
  • iburyak
    Recognized Expert Top Contributor
    • Nov 2006
    • 1016

    #2
    Try this:


    [PHP]DECLARE @FileName varchar(8000), @bcpCommand varchar(8000), @PrintCommand varchar(8000)

    Select @FileName = 'c:\query_resul t' + replace(convert (varchar(20), getdate()),' ','_') + '.txt'

    SET @bcpCommand = 'bcp "select * from table_name" queryout "'
    SET @bcpCommand = @bcpCommand + @FileName + '" -U uid_here -P pwd_here -c'

    EXEC master..xp_cmds hell @bcpCommand

    SET @PrintCommand = 'TYPE ' + @FileName + '>\\severname\p rintername'
    xp_cmdshell @PrintCommand[/PHP]

    Good Luck

    Comment

    Working...