Remove header and footer export data from CSV to SQL Server - sql

I need to export data from CSV to SQL Server
My CSV file is like this
Name,CustomerID
A,1
b,2
End
I need to export only the data into the SQL Server table
A,1
b,2
I tried to work with BULK INSERT, but header is coming
I need to remove header and footer.
Is the only option is to create a bcp with format file
Any help appreciated.
Thanks

You can use first_row and last_row options. If there are 100 rows set first_row=2 and last_row=99

Related

Exporting data in CSV file format from SQL?

I am trying to export a data table from SQL Server to a .CSV file format, but could not proceed any further after this warning. And I don't know how to fix this, and I need to go further in my job.
Write a query to retrieve the data you want to export
Right click on the result and save as csv file. see image bellow

Export Hive Query Results

I'm new to hive and could use some tips.
I'm trying to export query results from hive as a csv. When I try to pipe them out of CLI like:
hive -e 'select * from table'>OutPut.txt
I get a text file that has all the records but doesn't have the column headers. Does anyone have a tip for how to export the query results with the column headers, to a csv file?
If I run the query in hue, and then download the results as a csv I get a csv with the column headers but no records. If anyone has a tip on how to download query results from hue with records and column headers, I would greatly appreciate it too.
To export the column headers, you need to set the following in the hiverc file:
set hive.cli.print.header=true;
To get just the headers into a file, you could try the following:
hive -e 'set hive.cli.print.header=true; SELECT * FROM TABLE_NAME LIMIT 0;' > /file_path/file_name.txt
Having the column header but missing data is a known issue: HUE-544
The workaround is to use Hue 3 or more or switch to HiveServer2 (recommended starting from CDH4.6).

How to get the data type of table of csv or text file that is exported from sql server 2008

How to get the data type details of the table that is exported from SQL Server as txt or csv file on bulk export ?
Can any one please suggest me on this...
Thanks,
Harl
Use a Format File:
When you bulk import data into a SQL Server table or bulk export data from a table, you can use a format file to store all the format information that is required to bulk export or bulk import data. This includes format information for each field in a data file relative to that table.

Which one is good way to Import Excel to Database?

Hi i am using SQL Server 2008.
How can I import an Excel file into the database, which is the easiest way and simple to do?
OpenRowSet
BulkCopy
Linked Servers
SSIS
I have the above options to Import Excel to Database.
In my opinion SSIS wizard is best way to import excel data where you get row and column wise whole view of table data which will be inserted and also specify column names and contraints and parse data using query.
UPDATE :
If the data in your excel file does not require any processing to match your database table then I recommend you save your excel file as a csv and use a combination of BULK INSERT and the BCP.exe program.
To use BULK INSERT you will need a format file which defines how your datafile matches up to your database table. You can write this by hand to match the existing database table or you can use the following command to generate the format file you need:
bcp [ServerName].[SchemaName].[TableName] format nul -c -f [FormatFileOutputName].fmt -S[ServerHostName] -U[DbUserName] -P[DbUserPassword]
Now you will have 2 files:
DatafileName.csv
FormatFileName.fmt.
Use BULK INSERT within Sql Server to insert your data.
Note: If the columns in your datafile are in a different order than your database table then you can simply edit the generated format file to have them map correctly.

How to write SQL Query that matches data from a .csv file to a table in MySQL?

Is it possible for me to write an SQL query from within PhpMyAdmin that will search for matching records from a .csv file and match them to a table in MySQL?
Basically I want to do a WHERE IN query, but I want the WHERE IN to check records in a .csv file on my local machine, not a column in the database.
Can I do this?
I'd load the .csv content into a new table, do the comparison/merge and drop the table again.
Loading .csv files into mysql tables is easy:
LOAD DATA INFILE 'path/to/industries.csv'
INTO TABLE `industries`
FIELDS TERMINATED BY ';'
IGNORE 1 LINES (`nogaCode`, `title`);
There are a lot more things you can tell the LOAD command, like what char wraps the entries, etc.
I would do the following:
Create a temporary or MEMORY table on the server
Copy the CSV file to the server
Use the LOAD DATA INFILE command
Run your comparison
There is no way to have the CSV file on the client and the table on the server and be able to compare the contents of both using only SQL.
Short answer: no, you can't.
Long answer: you'll need to build a query locally, maybe with a script (Python/PHP) or just uploading the CSV in a table and doing a JOIN query (or just the WHERE x IN(SELECT y FROM mytmmpTABLE...))
For anyone new asking, there is this new tool that i used : Write SQL on CSV file