views:

37

answers:

1

hi,

I am using sql server 2005,

I want create sql procedure will save data into csv file.

Below is the qurey I am trying but it is not creating any file in my system.

use PBMS_DocumationWorkflow
go
create proc s_bcpMasterSysobjects
as
   select   '"' + name + '"'
            + ',' + '"' + convert(varchar(8), crdate, 112) + '"'
            + ',' + '"' + convert(varchar(8), crdate, 108) + '"'
   from master..sysobjects
   order by crdate desc
go
declare @sql varchar(8000)
select @sql = 'bcp "exec PBMS_DocumationWorkflow..s_bcpMasterSysobjects"
                out c:\bcp\sysobjects.txt -c -t, -T -S'+ @@servername
exec master..xp_cmdshell @sql

please suggest the cause or give me sample code which works fine.

Thanks.

A: 

Try changing the "out" to "queryout"

Tom H.
I have tried already
MKS
When I made that change it worked fine for me. Are you sure that xp_cmdshell is enabled on your server?
Tom H.
I have already enabled xp_cmdshell for sql server. But still on able to create file however I am able to create file using declare @sql varchar(8000)set @sql = 'OSQL -S EIL-SW-DSK-038\SQLEXPRESS -E -Q "execute AlphaTripNotes.dbo.s_bcpMasterSysobjects" -b -o c:\bcp\sysobjects.csv'exec master..xp_cmdshell @sql, no_output
MKS
can you please suggest how I can send this file as attachment from sql server. I can have mutiple files for attachment.
MKS