Datatype for a column with both numbers and text in SQL Server? - sql

I am exporting data from Excel to a SQL Server table using SSIS. I have a column in Excel which contains numbers and text.
What is the best datatype that I could use in the created table in SQL Server for this column to make the export of data smooth?
The reason that I am asking this is because I tried the data transformation and only the data with numbers in the above mentioned column got loaded properly.
BTW I used nvarchar(255) for the above column.
Thank you
Edit: My table kind of looks like this
The rows with text in col3 and col4 are not copied into the table

If your excel column contains combined values of characters, numbers and alphanumeric, add IMEX=1 to the extended properties of excel connection manager.
https://www.youtube.com/watch?v=s3d-XIYuB7k
Thanks

Related

Data is displayed with different styles in the same column SQL

I am Working with Microsoft SQL Server Management Studio.
All values in my table are displayed, after I have made an INSERT INTO in the column BA (NVARCHAR (31)), in order to fill in missing values. They are displayed in a different format than the already existing values.
I already tried ALTERING the column to a different datatype (float) but it did not help either.
I expect the output of for example '5001100016' instead of '5.0011e+009'
Thanks for your help, I am very new to SQL

Excel Data values returned as null when load to SSIS

I have an odd thing happening with importing data from Excel to SQL Server.
This is my sample source data
The value become null after import to SQL Server
Basically, other part of excel work well. But only for this area, the value become null. The data type is float which I haven't convert it to numeric or nvarchar.
Thank you for your help.

Replacing Null Values Using Derived Column in SSIS

I have a data flow task which picks up data from a non-unicode flat file to a SQL Server table destination.
I'm using a Derived Column task to replace NULL values in a date column with the string "1900-01-01". The destination table column is a varchar data type.
I'm using this SSIS Expression (DT_STR,10,1252)REPLACENULL(dateColumn,"1900-01-01") and the task executes successfully but I still see NULLs instead of the "1900-01-01" string at the destination.
Why is this? I've tried replacing the column, adding a new column but whatever I do I still see NULLs and not the replacement string. I can see my new derived column in the Advanced Editor so can see no reason why this isn't working. Any help would be most welcome.
If your your source is non-unicode, why are you using DT_STR? varchar is a already a non-unicode data-type. You should just be able to do it with
REPLACENULL(dateColumn,"1900-01-01")
Also, did you put in a lookup transformation to update the column? Have you made sure the right keys are being looked up and updated?

SQL Convert from alphanumeric to numeric only

Ok, I have a table I am querying for an outside project. The table has a field that is alphanumeric but the external project can only support numeric data. The outside project is needing my data as an Excel spreadsheet so I am trying to just export my query to Excel which I can do but I can't seem to figure out if there is a simple convert feature to do this for me. The originating table has the field as VARCHAR(10). I tried CAST and CONVERT but no go. This is SQL Server 2012.
Thanks.

INT Inserted in SQL as NULL SSIS Package Excel to SQL

I have setup an SSIS package to take data from an excel file, and insert it into SQL.
The package takes the data from Excel, performs some Data Conversions, and then Inserts it into my SQL DB.
One of the columns in excel contains both text, and ints. Typically the values will be either: W2 or 1099.
In the data conversion data flow, this column is converted to: string[DT_STR], length: 50, Code Page: 1252 (ANSI - Latin I)
in SQL, the field it is going to is configured as a varchar(50).
For any row, where the column value in Excel is 1099, the data inserted into SQL, comes through as NULL.
I have no idea what could be causing this. I have similar conversions in other packages, that come through with no issues.
i have tried formatting the column in excel as text as well as re-creating the data conversion, with no luck.
Any suggestions of ways to get this to work properly appreciated. Please let me know if you need any additional information.
Is the data NULL in the Excel preview? You need to isolate whether this NULL is being provided by the Excel driver.
Anyway this sounds like the old IMEX=1 issue that has been around since forever.
http://microsoft-ssis.blogspot.com.au/2011/06/mixed-data-types-in-excel-column.html
Try adding IMEX=1 to your Excel connection string.