June 28, 2013 at 9:52 am
Hi,
I have imported data into a database from an excel file and some of the columns contain values are like (392.03), (2.25), (65.00). Actually these values are should be -ve values can you guys help me how to convert these into -392.03,-2.25,-65.00
June 28, 2013 at 10:10 am
SQL_Learning (6/28/2013)
Hi,I have imported data into a database from an excel file and some of the columns contain values are like (392.03), (2.25), (65.00). Actually these values are should be -ve values can you guys help me how to convert these into -392.03,-2.25,-65.00
So, you've loaded your numeric values into column of string data type.
Now you can convert these "string" values into numeric type using something like that:
CASE WHEN LEFT(YourCharColumn,1) = '(' THEN -1 ELSE 0 END * CAST(REPLACE(REPLACE(YourCharColumn,'(',''),')','') AS DECIMAL(15,2))
August 26, 2014 at 2:57 pm
how do i add that as an expression in the Derived Column Transformation Editor? my data is coming from a csv into a staging table which has numeric and decimal data types where the parenthesis values are. i am not able to add another physical table with different data type.
August 26, 2014 at 3:12 pm
What have you done so far to learn how to use the Derived Column Transform?
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
August 27, 2014 at 10:20 am
Not enough... I have tried the following in conditional split transformation editor and failed
REPLACE([QuantityUnits],"(","-")
REPLACE(QuantityUnits,')','')
I have tried the following in Derived Column Transformation editor and failed
REPLACE(REPLACE([QuantityUnits],”(“,”-”),”)“,””)
SUBSTRING([QuantityUnits],1,1) == "(" ? REPLACE(REPLACE([QuantityUnits],"(","-"),")","") : [QuantityUnits]
I have tried changing the data type in the flat file connection manager to string data type and that doesnt help
The csv file's problem columns have negative values that are represented like (2.5) and values with over 3 digits represented like " 1,074 ". The quotes are handled by my specification of the text qualifier but I am stuck on converting the negative values.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply