How can i import from binary to float in SSIS? - sql

Im working on SSIS 2008.
I have an issue when i tried to import a flat file that is on binary. I had no problems with the normal records but when i tried to read a float number, it didn't recognized. I tried differents ways and also saw for a Unpack Decimal component, nothing works. In the last attempt i get the number in hexadecimal notation but dont know how to convert it into a float number.
I get something like this when i see the record on SQL:
Column 1 Column 2 Column 3
Cx0000000000500013 Cx0000000000000310 Cx0000000000000056
Thanks for help.

Related

SQL Server string to int error when importing CSV

I am trying to import a csv file into SQL Server 2017 using bulk insert. Most of the int columns, except the primary key have NULLs (as blanks in the csv file) but when I import I get an error that it can't convert a string to type int for the specified target column. Since I don't know which column it is affected, I went and replaced all the blanks with 0s, but I still get the game error.
Here is what I get after I import:
I don't know what to do to make this work, but it doesn't seem to make sense to me.
The issue is not the NULLs. There is a column in your CSV that your are expecting to contain only integer values, but it in fact contains string values that cannot be converted to integers.
Here would be an example:
my_str_to_int_col
1.0
2.0
3.O
4.0
5.0
...
Notice that 3.O should actually be 3.0
So you need to determine which column you are converting to an integer contains non-integer values.

the resulting value is outside the range for the data type decimal/numeric(31/31)

I have a complex sql which has more than 1000 row so I can't paste it here. I am using derby in memory db. When ı run my sql I get this error : the resulting value is outside the range for the data type decimal/numeric(31/31).
How can I fix it? any idea?
you can use a truncate function... really your trouble is that your decimals are more that your precision.. for example.. if you hace a decimal (10,2) it means that you can hace until 2 decimals... (counting for your 10 in numbers), you cant use 123456789.123 beacause your number of digits are mor than decimal (10,2)... if you need more info you can visit this link. Link info decimal sql server

Bigquery SUM(Float_Values) returns multiple decimal places and Scientific Notation

I am trying to calculate Total Sales at a store. I have product Price in a column called UNIT_PRICE. All the prices have 2 decimal places example: 34.54 or 19.99 etc and they are imported as type:float in the schema. (UNIT_PRICE:float)
When I perform the select Query: "SELECT CompanyName, SUM(Unit_Price) as sumValue" etc I get the following returned in the column, but only "sometimes".
2.697829165015719E7
It should be something like: 26978291.65
As I am piping this out into spreadsheets and then charting it I need it to be in the type float or at least represent a normal price format.
I have tried the following but still having issues:
Source: Tried converting original data type to BigDecimal with only 2 decimal points in the source data and then exporting to the csv for import into bigquery but same result.
Bigquery: Tried converting to a string first and then to a float and then SUM but same result. "SELECT CompanyName, SUM(Float(String(Unit_Price))) as sumValue"
Any ideas on how to deal with this?
Thanks
BigQuery uses default formatting for floating point numbers, which means that depending on the size of the number, may use scientific notation. (See the %g format specifier here)
We tried switching this, but it turns out, it is hard to get a format that makes everyone happy. %f formatting always produces decimal format, but also pads decimals to a 6 digit precision, and drops decimals beyond a certain precision.
I've filed a bug to allow an arbitrary format string conversion function in BigQuery. It would let you run SELECT FORMAT_STRING("%08d", SUM(Unit_Price)) FROM ... in order to be able to control the exact format of the output.
Do you see this in the BQ browser tool or only on your spreadsheet?
BQ float is of size of 8 bytes, so it can hold numbers >9,000,000,000,000...
I find it that sometimes when Excel opens a flat file (csv) it converts it to the format you mentioned. To verify this is the case, try to open your csv with notepad (or other flat file editor), before you try with excel.
If this is indeed the issue, you can configure the excel connector to treat this field as string instead of number. other option would be to convert it to string and concat "" to the number. this way the spreadsheet will automatically treat it as string. afterwards you can convert it back to number in the spreadsheet.
Thanks

Bulk insert field and then convert it from CHAR to DECIMAL

I am using a bulk insert to import data from a CSV file. One of the fields is a number, and I import it as a DECIMAL(4,3). However, this data file has a few values where the number is "3.2342e-05". This obviously throws an error since this is a char. How can I convert this number to zero? For my purposes, I plan to consider any number that small as a zero anyway.
I figure that I will be importing the data into a temp table (staging table) first, so that I can clean it up in there, and then I will be inserting it from there into my final table.
SQL Server 2008
EDIT: One thing I am considering is importing the data as a char and then converting the column type, and then using a CASE statement to set anything greater than 1 to a zero. This field should never be greater than 1, which is why I am able to do this.
This is recognised as float, so you can double CAST via float

loading data from excel to sql

I am loading data from excel sheet to sql using SSIS package. When I load data into table1 using the datatype varchar(255) for all fields, I had no problem. But, when I tried to load data from table1 to table2 it showed an error : can not convert datatype varchar to numeric.
All of the fields in table2 have valid datatypes. Now when I look at the data in table1 for the field (its datatype is decimal(5,2) in table2) which was giving me that error, I saw one of the record had a value of "2.9999999999999999E-2" in table1. The same record in the excel sheet is 0.03.
In the same column there is a record with a value of 0.01. Why did it change the value for 0.03? Do I have to convert the data in excel sheet? I want to load records from excel sheet the way they are.
I am using sql server 2005.
Thanks
Odds are, that the 0.01 value is in a text cell in excel, while the 0.03 is in a numeric cell. Your library sees that it has a number, and tries to import it numerically. Floating point numbers can't represent certain numbers perfectly, which leads to your error.
One way to solve this is to mark the cells in the original spreadsheet as text, or if your library has the capability, mark them as text when importing the values.
Have you considered checking the connection string, particularly IMEX=1? This worked for me when I was facing similar issues in the past.
http://www.connectionstrings.com/excel
Sorry for the digging up of a 5 year old post, but it looks like a lot of people have looked at it.
I ran into a similar issue with numbers from excel coming over in the Scientific Notation format
Try:
CONVERT(FLOAT, [Your Column Here], 2)
Then wrap it into whatever type you need
Apparently when you get the Scientific Notation format don't work as expected.
This is how I found the answer see Quassnoi's post