Excel date insert to SQL Server table as 44381 - sql

I'm facing problem when Excel date column data were import SQL Server table through Logic apps.
Excel value shows as 7/4/2021 column. which was need import is a varchar column in the table. After data import it shows as 44381. Is there any solution for it.

Did you preview the data before run the pipeline? I tested load the same data from excel file to SQL table varchar column, everything works well. We can't repeat you error. Please check if there are any different steps between you and I.
This my source excel file:
Source dataset preview:
These three columns are both considered as String data type. My sink table schema and pipeline output:

Related

Importing date data from excel into table with right format conversion

I am importing data from excel files into SQL server database. In excel ,Date field are in the format mm-dd-yyyy. Whereas SQL database imports it as yyyy-mm-dd, swapping dates to months.For ex. in excel its 01-12-2018 but in SQL it imports as 2018-12-01. Hence the dates are incorrect.
Please let me know a way to import it correctly in SQL.
I am happy to import in both ways : yyyy-mm-dd or yyyy-dd-mm. I just want it to read the date correctly form excel file.
I am using import export wizard.
Updated answer:
OP mentioned in another answer comment
I am currently using import export wizard to import data.
To solve problem in Import export wizard.
Choose Flat file source - I used a sample file (sample.csv) with this data
id, dates, text
1,08-09-2018,"sample"
2,05-09-2019,"more sample"
Under Choose your data source I went to Advanced tab and ensured that dates are imported as string.
At the Select Source Table and Views step, go into Edit Mappings>Edit SQL and then change the table creation query to have an extra calculated column (say cdates) with definition like [cdates] as convert(date,[ dates],110). As you can see I added this in my SQL as last column in definition.
In the case that you don't create table but insert into existing table. Alter the table to have a calculated column over the varchar date column.
See the output I got
Original Answer:
You should import the dates as nvarchar(10) into the table and then cast them after they have been imported.
Typically nvarchar type structure is followed for all purpose and is also called staging tables. In staging tables most of the relevant mistrusted data fields are of nvarchar(N) type allowing them to be successfully imported into SQL server.
After import, you should take data from staging tables into desired tables using properly casted/converted columns in a MERGE or UP-SERT query.
In you case you should use explicit convert like
CONVERT(date,your_staging_date_column ,110)
If data is set as Date in Excel, you can convert it to nvarchar, and then back to date as follows:
CONVERT(date, convert(nvarchar, [date from excel]), 110);
110 in the end means that it will convert from format mm-dd-yyyy as your data is currently formatted in Excel.
If you are reading data from Excel as pure text, then it will be enough to convert that text to date:
CONVERT(date, [date from excel], 110);
This function will convert data to correct format in your table.

Populating SQL database table by retrieving data from Excel spreadsheet

I'm new to SQL (but have experience in other programming languages) and I'm taking on a side project at work that involves creating a database of our team's financials. Ultimately what I want to do is have this database retrieve data from a specific table in a worksheet and then populate a database table. I'm sure this is possible but how would I go about doing this? I'm currently familiarizing myself with PostgreSQL as I found it to be the most beginner friendly.
I am using Dbeaver where i can export the data of any table in to CSV , once i have data in CSV , i can create .sql file back using online http://codebeautify.org/csv-to-sql-converter which then can be executed on any other same db.
This will help get you a cell range exported to CSV:
Export sheet from Excel to CSV
Then use this to get the CSV into PostgreSQL:
How to import CSV file data into a PostgreSQL table?

SSMS - Importing into nvarchar(max) still giving truncate errors

I'm using SSIS to import an Excel table into SQL Server.
The field in the SQL Server table is set as nvarchar(max) but it still gives me Truncate Error.
The column that I want to import can have any number of characters, it could be 1 or it could be 10,000. It's a free-text filed without any limitations.
Go into the Advanced settings of your Excel Source Component, and manually set the length of the Output columns.
SSIS samples your data to get an idea of each column. It will use the max length of the sample to determine the "proper" field size. Of course this causes constant issues.
Can you add something to order your data to make the longest first?
ORDER BY LEN(LongFIELD) DESC
Check out StackExchange for more info:
Text was truncated or one or more characters had no match in the target code page When importing from Excel file

How to insert values with out scientific notation in ssis package creation?

I developing package for import data from excel to SQL DB using SSIS.
In one of the excel sheet following value present no format is used it's general .
0.0000316
0.0000088
0.0000022
0.000001
I insert above value into DB following data present in DB. in DB it's float data type.
3.16E-05
8.8E-06
2.2E-06
1E-06
How to insert without E . I need to insert same value in excel sheet. It's possible?
The data in the database is exactly the same data in the Excel. The only difference is the way in which it's shown. I don't know what are you using that data for, but I can assure you that you'll get the same data when fyou do calculations as you would in Excel (Excel also uses flotaing point numbers).
If you need, for some reason, to see the query results in a particular format, use SQL Server FORMAT function.

Excel database values to SQL Server and different tables

I got an Excel file with data which I want to import into a database in Microsoft SQL Server 2008 Express edition.
I do this with right click on a database -> task -> import data.
After this, my data from Excel is loaded in the database in one table.
But I want to seperate the columns from the Excel file into different tables.
So instead of loading all Excel data into one database and table, I want to load the Excel data into one database, but in different tables.
For example: Save column 1,2,3 from Excel in table A, and save column 4,5,6 from Excel in table B.
Anyone that knows how to do this?
I followed the suggestion of #bendataclear:
"Personally I would just import into a temporary table then write INSERT INTO X SELECT queries to move in the correct columns."