|
|
|
Say Hey Kid
      
Group: General Forum Members
Last Login: Tuesday, May 07, 2013 6:56 AM
Points: 679,
Visits: 953
|
|
Hi,
I need to create a stored procedure that accepts a parameter, this paramentes is a name. When i pass the name to the stored procedure, this procedure creates a empty txt file with the name that i passed as the parameter.
Is it possible to do this using t-sql?
Thank you
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, January 15, 2013 11:17 AM
Points: 13,
Visits: 28
|
|
I can't believe this is the slickest way to achieve what you're after, but this works 
CREATE PROCEDURE EXPORT_DATA @FileName varchar(255) as begin
declare @bcpCommand varchar(255), @Result int set @bcpCommand = 'bcp "Select 1 as a" queryout "' + @FileName + '" -c -t, -T -S ' exec @Result = master..xp_cmdshell @bcpCommand, no_output
end
Don't forget that xp_cmdshell is not enabled in the db configuration by default
Mike.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, October 07, 2010 3:51 AM
Points: 1,
Visits: 1
|
|
| Is there any other way to create store procedure
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 8:49 AM
Points: 133,
Visits: 413
|
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Thursday, November 22, 2012 5:47 AM
Points: 33,
Visits: 103
|
|
Hi,
Here the txt file will be created in server. Is it possible to create a file in local machine?
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Monday, February 11, 2013 2:30 PM
Points: 225,
Visits: 350
|
|
| The file will be created from the context of the sql server, so you should be able to write it to any drive or share the sql server has access to.
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 8:49 AM
Points: 133,
Visits: 413
|
|
A little more information would be nice as to what the big picture of this is... Is the parameter some data that needs to be retrieved from SQL? I could whip out a VBS script to hit the DB, grab the value, and pump it into the script. Powershell possibly?
Director of Transmogrification Services
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: 2 days ago @ 5:50 AM
Points: 810,
Visits: 1,195
|
|
Why not use an SSIS package to generate the file?
|
|
|
|