SQL wont import because the data will be truncated. How do get it to just cut the string off at 16 characters - sql

I need to import a .CSV file into a SQL Server table. In the table, one of the columns is of datatype varchar(16), but in the .CSV Excel file, most of the entries in that column are 25 characters or more. I need SQL Server to just cut the string off at 16 characters and import that. How to I do this? I have no idea how to even start to code this
I import this into a table using the AnySQL Maestro import wizard by
right clicking the table
clicking data management
clicking import
selecting .csv as the file type
selecting which columns from the .csv match up with which columns in the sql table
clicking OK.
If the field in the .csv was the right size, there would be no issue importing

Simple solution
Open your .CSV file with Excel.
In Excel keep first 16 characters and remove others (search left function)
Use SQL Server Management Studio to import data from Excel file

Related

Query contains parameters but import file contains different values [importing csv to Teradata SQL]

I am using Teradata SQL to import a CSV file. I clicked import to activate the import operation, then typed the following
insert into databasename.tablename values(?,?,?,...)
I made sure to specify the database name as well as what I want the table to be named, and I put 13 commas--the number of columns in my CSV file.
It gives me the following error:
Query contains 13 parameters but Import file contains 1 data values
I have no idea what the issue is.
The default delimiter used by your SQL Assistant doesn't match the one used in the CSV, so it doesn't recognise all the columns.
On SQL Assistant, go to : Tools >> Options >> Export/Import and choose the proper delimiter so it matches the one in your CSV.

Import data into SQL Server from an Excel file

I have an Excel (version 2007) file which has more than 700 columns and I need to import that data into my SQL Server database. When I import the data, it only imports the first 255 columns as columns in table that is created by SQL Server. I want to know how to import all 700 columns.
You can try saving the excel data file as a text delimited file, then choose "flat file" in DTS. That should solve your problem.
Here is another solution to the problem as well: https://waheedrous.wordpress.com/2014/01/14/ssis-importing-an-excel-file-with-over-255-columns/

Script to import ever changing Excel CSV file into SQL Server Express 2008

I have looked at this site and several other, and the closest I could come to was Dealing with a changing Excel table structure to import to a database table
But I'm actually looking for the script to identify the Column Name and Type from the CSV file, and to create the Table from that.
The actual Importing script is working well, but it only caters for fixed Headers, while I have headers varying between 160 and 170 during any given time.

How to import pipe delimited text file data to SQLServer table

I have database table represented as text file in the following pattern:
0|ALGERIA|0| haggle. carefully f|
1|ARGENTINA|1|al foxes promise|
2|BRAZIL|1|y alongside of the pendal |
3|CANADA|1|eas hang ironic, silent packages. |
I need to import this data to a SQL Server 2008 database table. I have created the table with the types matching the schema.
How to import this data to the table?
EDIT: Solved by following the answer selected.
Note to anyone stumbling upon this in future: The datatype needs to be converted.
Refer: http://social.msdn.microsoft.com/Forums/en/sqlintegrationservices/thread/94399ff2-616c-44d5-972d-ca8623c8014e
You could use the Import Data feature by right mouse clicking the database, and then clicking Tasks then Import Data. This will give you a wizard which you can specify the delimiters etc. for your file and preview the output before you've inserted any data.
If you have a large amount of data you can use bcp to bulk import from file: http://msdn.microsoft.com/en-us/library/ms162802.aspx
The bcp utility bulk copies data
between an instance of Microsoft SQL
Server and a data file in a
user-specified format. The bcp utility
can be used to import large numbers of
new rows into SQL Server tables...
Except when used with the
queryout option, the utility requires
no knowledge of Transact-SQL. To
import data into a table, you must
either use a format file created for
that table or understand the structure
of the table and the types of data
that are valid for its columns.

BCP utility to create a format file, to import Excel data to SQL Server 2008 for BULK insertion

Am trying to import Excel 2003 data into SQL table for SQL Server 2008.
Tried to add a linked server but have met with little success.
Now am trying to check if there's a way to use the BCP utility to do a BULK insert or BULK operation with OPENROWSET, using a format file to get the Excel mapping.
First of all, how can I create a format file for a table, that has differently named columns than the Excel spreadsheet colums?
Next, how to use this format file to import data from say a file at: C:\Folder1\Excel1.xsl
into table Table1 ?
Thank you.
There's some examples here that demonstrate what the data file should look like (csv) and what the format file should look like. Unless you need to do this lots I'd just hand-craft the format file, save the excel data to csv, then try using bcp or OPENROWSET.
The format file specifies the column names for the destination. The data file doesn't have column headings so you don't need to worry about the excel (source) cols being different.
If you need to do more mapping etc, then create an SSIS package. You can use the data import wizard to get you started, then save as SSIS package, then edit to your heart's content.
If it's a one-off I'd use the SQL data import size, from right-click on database in mgmt studio. If you just have a few rows to import from excel I typically open a query to Edit Top 200 rows, edit the query to match the columns I have in excel, then copy and paste the rows from excel into SQL mgmt studio. Doesn't handle errors very well, but quick.