Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Save stored prodeure result as file

Author  Topic 

chiragvm
Yak Posting Veteran

65 Posts

Posted - 2012-12-13 : 04:53:23
i have a Stored Procedure , in proc Print certain result like

Print '-- Start Transection--'
Print 'Transection No = ' + @TransectionId
...
...
Print 'Transection Success'
Print '-- End Transection--'

is it possible to Save printed result in a file while call it from UI. after that we have to mail that file to user also ask for download that file

-------------
Chirag
India
Sr. Web Engineer

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-12-13 : 05:01:49
Yes.
You can bcp the result out.
Use sqlcmd to run it and output to a file
Use it as a source in ssis
Use reporting services
...



==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-12-13 : 05:02:24
Check this link http://www.nigelrivett.net/SQLTsql/WriteTextFile.html

--
Chandu
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-12-13 : 05:22:41
One example is as follows:

GO
CREATE PROC test_Proc
AS
BEGIN
SELECT 'example for writting procedure output to a file'
END
GO
EXEC master..xp_cmdshell
'bcp "EXEC [DBName].[dbo].[YourSPName] " queryout "D:\temp\file.txt" -c -S "YourServerName" -T'

Change file path and then execute it

http://social.msdn.microsoft.com/Forums/en-US/sqlgetstarted/thread/e2d012d5-51d8-4a63-99cc-e76d8498ef94/

--
Chandu
Go to Top of Page
   

- Advertisement -