Import/Export Wizard and quote delimiter issue - sql-server

Why I am getting the following error, and how can we fix it?
Error 0xc0202055: Data Flow Task 1: The column delimiter for column "Col1" was not found.
(SQL Server Import and Export Wizard)
I'm using the latest version (18.11..) of Microsoft SQL Server Management Studio (SSMS) to import data from a 500MB text file that has | as a column terminator. As shown in the image below, I'm using Text Qualifier as double quotes " and there is no | character inside the Col1 column, and the column is delimited by |.

Related

How to overcome truncation error?

I am trying to use the import and export wizard to move a small data set from a CSV file to an existing (empty) table. I did Script Table As > Create To, to get all DML for this table. I know the field type of the two fields which are causing problems is varchar(50). I'm getting this error message:
Error 0xc020902a: Data Flow Task 1: The "Source - Reconciliation_dbo_agg_boc_consolidated_csv.Outputs[Flat File Source Output].Columns["ReportScope"]" failed because truncation occurred, and the truncation row disposition on "Source - Reconciliation_dbo_agg_boc_consolidated_csv.Outputs[Flat File Source Output].Columns["ReportScope"]" specifies failure on truncation. A truncation error occurred on the specified object of the specified component.
(SQL Server Import and Export Wizard)
The max length of all characters is 49, so I'm not sure why SQL Server is complaining about truncation. Is there any way to disable this error check and just force it to work? It should work as-is! Thanks everyone.
Is there any way to disable this error check and just force it to
work? It should work as-is! Thanks everyone.
Yes. If you're using the wizard, you can view the table schema before running it, and check the option to ignore truncation.
The max length of all characters is 49, so I'm not sure why SQL Server
is complaining about truncation.
The default datatype of source column may be Text while using import wizard, so change it to varchar(50) using advanced tab of source. Check this link for more details.
For the safe side can you please check column data type in both Source and Destination. If both are not same just declare all your columns as varchar inside table with some maximum length say for example varchar(max) or varchar(500) and see what would be the result.
Change max length of Varchar column:
ALTER TABLE YourTable ALTER COLUMN YourColumn VARCHAR (500);
Then the column will default to allowing nulls even if it was originally defined as NOT NULL. i.e. omitting the specification in an ALTER TABLE ... ALTER COLUMN is always treated as.
ALTER TABLE YourTable ALTER COLUMN YourColumn VARCHAR (500) NULL;
check column nullable or Not nullable based on requirement just change it.
Use below steps for better understanding How to import a CSV file into a database using SQL Server Management Studio:
While bulk copy and other bulk import options are not available on the SQL servers, you can import a CSV formatted file into your database using SQL Server Management Studio.
First, create a table in your database into which you will import the CSV file. After the table is created:
Log in to your database using SQL Server Management Studio.
Right click the database and select Tasks -> Import Data...
Click the Next > button.
For Data Source, select Flat File Source. Then use the Browse button to select the CSV file. Spend some time configuring the data import before clicking the Next > button.
For Destination, select the correct database provider (e.g. for SQL Server 2012, you can use SQL Server Native Client 11.0). Enter the Server name; check Use SQL Server Authentication, enter the User name, Password, and Database before clicking the Next > button.
In the Select Source Tables and Views window, you can Edit Mappings before clicking the Next > button.
Check Run immediately and click the Next > button.
Click the Finish button to run the package.

Export data to csv having datatype ntext SQL server

I want to export data from SQL server to CSV format but having issue with ntext dataype in some tables columns.
data is ntext column is html with html tags like br , li etc..
BRANDS SUBSECTION:BEAUTY, FRAGRANCE, GROOMING & HEALTH
Acticare
abc def PR
abc def T: 020-0000 1230 e: abc#abc.com
Added Dimension Dentistry
abc def PR
abc def T: 012-3456 7689
I have tried export from SQL server direcly exporting to csv format , tried SSIS package,even tried converting to varchar then export but when exported data is not showing correctly.
How do I export data to excel/csv having column data type ntext containing html tags ??
When you are selecting the columns in the CSV file destination, try setting the Data Type for the source column to
text stream [DT_TEXT] or Unicode text stream [DT_NTEXT] (as the case maybe).
I'm using SQL Server Export Wizard.
In the choose destination be sure to use a Delimited Format with a double quote text qualifier.
Cast the column in the select statement
CAST([Message] as NVARCHAR(255)) as Message
(Message is defined as ntext)
Use a comma delimiter
...then map to DT_NTEXT in the export wizard

Import from MSSQL to Excel when the data contains embedded line breaks

I am trying to export a sql query (MS SQL 2014) into excel 2010. The problem is column values contain line breaks, so the remaining data gets copied to the next line in excel. Is there a way to get rid of this? Keeping the column as is? or maybe encapsulating the column so the sql considers it as one column and ignores the line breaks?
Here is my SQL Query:
select * from tbl_case
where (casenature not like '%<strong>%'
and casenature not like '%<br />%'
and casenature like '%from:%')
and userid in (select employeelogin from tbl_employees where riding='15010')
Works fine if I use the normal way to import data from MSSQL to Excel which is: in Excel, Data->From other sources->SQL server.
To import data resulting from an arbitrary SQL query:
At the last step of the wizard (where you select the range), press Properties...
In the resulting Connection properties window:
Definition->Command type - SQL
In the Command text field, write your query
You can replace enter keys with space in select statement, and then export to Excel

SSIS the Percentage column from Excel -> SQL Server

I am trying to create a SSIS package that will import Excel data to SQL Server 2000 database.
One of the column in Excel sheet is in Percentage format and I wish to import that column in string format so it displays 45.22% instead of 0.4522.
Is there a way of doing this within SSIS?
Use derived column to add new column based on expression:
(DT_WSTR,20)(COL1 * 100) + "%"
It multiplies COL1 by 100, converts it to WSTR (unicode string) and adds percent-sign at the end.

Can't import as null value SQL Server 2008 TSV file

I import data from a TSV file with SQL Server 2008.
null is replaced by 0 when I confirm a table after import with integer column.
How to import as null, please Help me!!
Using bcp, -k switch
Using BULK INSERT, use KEEPNULLS
After comment:
Using SSIS "Bulk insert" task, options page, "Keep nulls" = true
This is what the import wizard uses: but you'll have to save and edit it first because I see no option in my SSMS 2005 wizard.
This can be set in the OLE DB Destination editor....there is a 'Keep nulls' option.
Alternative for those using the Import and Export Wizard on SQL Server Express, or anyone who finds themselves too lazy to modify the SSIS package:
Using text editing software before you run the wizard, replace NULLs with a valid value that you know doesn't appear in your dataset (eg. 987654; be sure to do a search first!) and then run the Import Export Wizard normally. If your data contains every single value (maybe bits or tinyints), you'll have some data massaging ahead of you, but it's still possible by using a temporary table with datatypes that can store a greater number of values. Once it's in SQL, use commands like
UPDATE TempTable
SET Column1 = NULL
WHERE Column1 = 987654
to get those NULLs where they belong. If you've used a temporary table, use INSERT INTO or MERGE to get your data into your end table.

Resources