What is the command line option to bcp out a table into a file in the PC/IXF format so that it can be read by another DBMS(db2)
Or, how to convert a bcp out .txt file to a PC/IXF file format
Related
I'm creating a batch file to run a stored procedure and write my result into CSV from a table in Google BigQuery. My batch file script is like this:
set target_dir=C:\Temp\
call bq query --use_legacy_sql=false "call mydataset.sp_test()"
bq query --format=csv --max_rows=3000000 --use_legacy_sql=false ^
"select * from mydataset.test" > %target_dir%TEST_%date:~6,4%%date:~3,2%%date:~0,2%.csv
The default delimiter of my .csv file is a comma ,
how can I change the delimiter to a pipeline | or other specified delimiter in my batch file script?
My copy into command is as follows:
"COPY INTO "+ #[User::SchemaName] + "." + #[User::tableName] + " file_format = (field_delimiter = '|',null_if = ('NULL', 'null'),empty_field_as_null=false,validate_UTF8=false)"
After copying when I do select distinct on a column the output is as shown below.
Is there anything wrong with my copy into command? Or the flat file?
You will have to examine your flat file. You have asked not to validate the utf8 data in your file format and also empty_field_as_null=false .
Examine your flat file to check if it is having any non utf8 characters and set the proper encoding.
you can use the file command on the flat file to see if it has any non utf values and based on that set the encoding.
example :
file ITEM_STACK.1
ITEM_STACK.1: ISO-8859 text, with very long lines
Review the table in the following documentation for the encoding values
https://docs.snowflake.net/manuals/user-guide/intro-summary-loading.html#supported-character-sets-for-delimited-files
exec master..xp_cmdshell 'bcp " Select 'column' union all Select "
cast(column As nvarchar(max))from [NEWDATABASE].[dbo].[TempPower] WHERE BarCode = 'batman'"queryout D:\TempPower.xls -o "D:\querycommanddetails.txt" -T -c -C RAW'"
bcp does not, from the documentation I can find, export to any Excel binary format. What you're doing is producing a delimited text file and giving it an Excel extension. But file extensions don't dictate how the data is stored/represented in the file; they're just a hint to tell Windows what application to open them in and the application a hint about how to process it.
If you open the file in a text editor, you'll see the raw data in plain text there. Excel may even give you a warning when you attempt to open a delimited text file that has the xls extension because it's not getting what it expected.
If you need to output directly to a xslx file, you'll need to produce it through another method.
So i am converting excel files into a .txt files using vbs, and the input file name needs to be the same as the output file name with the changed file extension obviously. Whats making this so hard is the fact that I using this as basically a file converter so the names of the files will be random.
The way I load the input file is by is using the %1 command and just pass in the input file after I call the batch like this.NOTE: the .xlsx can be changed to any .xlsx file that i need to convert.
C:\tabdim>conversion_batch_file.bat **C:\tabdim\2160707.xlsx**
In the batch file (C:\tabdim\conversion_batch_file.bat) Note: the rest of the sql has been replaced with x's.
%windir%\SysWow64\wscript.exe C:\tabdim\combined.vbs **%1**
sqlcmd - xxxxxxxxxxxxxxxxxxxx
bcp xxxxxxxxxxxxxxxx "**C:\tabdim\20160707.txt**" xxxxxxxxxxxxxx
sqlcmd - xxxxxxxxxxxxxxxxxxxx
If there was any way to do something like this
"%1- last 4 characters+".txt""
I know that is totally wrong syntax, I'm just kind of using words to describe kind of what I'm trying to have happen.
I need to convert a unicode text file (19,000K) to an ANSI text file for use with Essbase.
I currently have this written to convert the file but only the first 7800 lines are copying.
This is what I have in my .bat file
cmd /a /c TYPE PVTBHFM_20160708.dat > PVTBHFM_ANSI.dat
What am I missing to fully convert this file?
Is there a way to save the file in a different location?