DECLARE @cmd varchar( 250),@way varchar (100)
select @way='"C:\Program Files\Microsoft SQL Server\100\Tools\binn\bcp" '
select @cmd = @way +' database.dbo.' + 'table' + ' out ' + 'c:\' +
'table' + '.txt -S ' + @@servername + ' -c -t, -U sa -P password'
select @cmd = 'master..xp_cmdshell ''' + @cmd + ''''
exec( @cmd)
select @cmd
select @way='"C:\Program Files\Microsoft SQL Server\100\Tools\binn\bcp" '
select @cmd = @way +' database.dbo.' + 'table' + ' out ' + 'c:\' +
'table' + '.txt -S ' + @@servername + ' -c -t, -U sa -P password'
select @cmd = 'master..xp_cmdshell ''' + @cmd + ''''
exec( @cmd)
select @cmd