April 21, 2010 at 3:37 am
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
July 9, 2010 at 4:12 am
I can't believe this is the slickest way to achieve what you're after, but this works :w00t:
[font="Arial Black"]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[/font]
Don't forget that xp_cmdshell is not enabled in the db configuration by default
Mike.
October 7, 2010 at 3:52 am
Is there any other way to create store procedure
October 8, 2010 at 8:57 am
March 2, 2011 at 9:39 am
Hi,
Here the txt file will be created in server. Is it possible to create a file in local machine?
March 2, 2011 at 10:17 am
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.
March 2, 2011 at 10:31 am
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?
March 3, 2011 at 6:05 am
Why not use an SSIS package to generate the file?
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply