December 4, 2023 at 8:09 pm
Hello,
I need to put data from table to txt file as pipe on certain drive can someone assist me? Thank you
December 4, 2023 at 8:28 pm
i used this code:
EXECUTE master.dbo.xp_cmdshell 'bcp "SELECT * FROM dbo.CustomerInformation " queryout C:\Data\Objects.txt -t"|" -c -T ' and it is not working
December 4, 2023 at 9:27 pm
Does SQL Server have permissions to write to that folder?
Are you getting any error messages?
Are you executing in SSMS? If so, does the login have permissions to write to that folder?
In a SQL Agent job? If SQL Agent job, does the SQL agent login have permissions to write to that folder?
December 5, 2023 at 12:11 am
i used this code:
EXECUTE master.dbo.xp_cmdshell 'bcp "SELECT * FROM dbo.CustomerInformation " queryout C:\Data\Objects.txt -t"|" -c -T ' and it is not working
What is your definition of "Not Working" here?
--Jeff Moden
Change is inevitable... Change for the better is not.
December 5, 2023 at 1:55 pm
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC Driver 13 for SQL Server]Unable to open BCP host data-file
NULL
December 5, 2023 at 4:13 pm
I need to know how to add headers please
If this is an Agent Job step then Powershell is a lot less hassle. Play with something like:
$SQLparams = @{
'ServerInstance' = '.';
'Database' = 'YourDB';
'ErrorAction' = 'Stop';
'Query' = 'SELECT * FROM dbo.table1' }
$MyPath = "G:\Backup\Test.txt"
Invoke-Sqlcmd @SQLparams |
ConvertTo-Csv -Delimiter '|' -NoTypeInformation |
% {$_ -replace '"',''} |
Out-File -Encoding ascii $MyPath
December 5, 2023 at 4:17 pm
My first replay seemed to time out so I posted again.
December 5, 2023 at 9:58 pm
this is not working
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply