Click here to Skip to main content
15,890,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friend,

I have to created excel file on pre define folder path if file not exist on that path and export data from sql query. but I don't want to use for sql Wizard for same. I want create SQL store procedure for same and I will call that store procedure in Job.

But I want to create excel file and export data into it by store procedure only.

Thanks in advance.
Posted
Comments
So, what is the problem?

1 solution

Use below script

SQL
DECLARE @PATH VARCHAR(500)
DECLARE @Name Varchar(500)
DECLARE @SQL VARCHAR(500)

SET @Name = TableData.xls'

SET @PATH = '\\C:\'

SET @SQL = 'SELECT * FROM TableName'

DECLARE @cmd VARCHAR(800)
SET @Cmd = 'mkdir ' +@PATH
EXEC master..xp_cmdshell @cmd

DECLARE @FILENAME VARCHAR(200)
SET @FILENAME = @PATH + @Name

EXEC sp_makewebtask
  @outputfile = @FILENAME,
  @query = @SQL,
  @nrowsperpage = 40000,
  @lastupdated=0 ,
  @resultstitle = '  '
 
Share this answer
 
v2
Comments
Naresh Pansuriya 4-Dec-13 2:21am    
I got problem in sql Server 2008 R2 like below

Could not find stored procedure 'sp_makewebtask'

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900