Truncate Decimal In Derived Column Task
Apr 10, 2008Hi,
Is there a way to truncate a number to a certain number of decimal places in the SSIS Derived Column component (similar to TRUNC in excel)?
Thanks!
Hi,
Is there a way to truncate a number to a certain number of decimal places in the SSIS Derived Column component (similar to TRUNC in excel)?
Thanks!
how to declare multiple derived columns in SSIS Derived Column Task in one attempt.as i have around 150 columns coming from Flat file. I had created the required Expression in Excel and now i want add those in derived column task but its allowing only 1 expression at a time.
View 4 Replies View RelatedI want to replace the contents of a value column with itself but rounded to 2 decimal places.
The current column is a double and I have tried to perform this using the following expression but it fails to work.
Code Snippet
Round(cc_vl,2)
How should I achieve this?
We are importing Flat file data from our Mainframe system. We have a lot of money amounts coming in, but the mainframe does not store the decimals in the flat file. So for example a row in the file might look like this:
+0000007894-0000000563
Where the first value is $78.94 and the second value is -$5.63
Is there anyway to have the Flat file connection manager put in the decimal place for me, or do i have to create derived columns for each column and divide it by 100? There like 50-100 columns per file, so i'm looking for a better, quicker way.
Thanks in advance.
John
I have a excel file which has a column called "Code" and their values are A,B,C,D,E,F,G,H. I want to create a new column called "status" based on the values of "Code".
Code:
A
B
C
D
E
F
G
H
If A,C,E,G then "status" = "Active" else if B,D,F,H then "Status" = "Inactive". I like to do it using "Derived Column".
How do you replace quotes in an expression
I mean for example if I needed to replace xx in a string with empty string then the following works: REPLACE(SelectedString, "xx","")
But the example I have needs to actually replace quote marks in a string with an empty string and REPLACE(SelectedString, " " ","") doesn't work. I tried guessing a few option like "E or &QTE or something...
Any ideas ?
Thanks
Richard
I am moving data from an oracle database to sql server. Two of the source fields are dates, which sometimes contain values I know to be incorrect ('0001/01/01' and '1900/01/01').
I'd like to use either the derived column or script task (or any other appropriate one) to update these incorrect values (in both columns) to null before inserting into sql server, smalldatetime field.
In sql 2000 dts, I would simply use a VBScript IF statement, but I'm somewhat clueless when it comes to .Net.
Does anyone have any ideas or sample code that may help?
Thank you much.
I have a package that fails as soon as it hits the first Data Flow that contains a Derived Column task. The task takes three date columns and looks for a date of 6/6/2079. If it is there, it is replaced with a NULL. This task worked fine until I installed the Non-CTP version of SQL 2005 SP1, earlier today. (I went from RTM 9.0.1399 to SP1 9.0.2047)Does anyone have any ideas?
Here is the error I am trapping:
An error occurred while evaluating the function.
The "component "Update Max Date Value to NULL" (346)" failed because error code 0xC0049067 occurred, and the error row disposition on "input column "WeekEndingDate" (455)" specifies failure on error. An error occurred on the specified object of the specified component.
The ProcessInput method on component "Update Max Date Value to NULL" (346) failed with error code 0xC0209029. The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running.
Thread "WorkThread0" has exited with error code 0xC0209029.
I tried to configure the error output to ignore the failure. The task succeeded. It did not insert anything, however, for the three columns in question. It then failed on the next Data Flow that contained a Derived Column task. I tried to pre-populate the columns with a default date, but no go. Any help would be appreciated.
i have too many DTS packages to migrate to SSIS, and while examining a DTS package in BIDS (converted with the migration utility) i tried to edit the resulting migrated package, which opened the DTS interface with the two connection icons joined by the big fat arrow with a gear on it...not exactly what i had in mind, iow, it looks like SSIS on the outside, but its still DTS on the inside.
So I stripped out a series of components from a more complex package hoping that simplifying it would reveal the contents of old DTS Transformations tab at least partially set up in a Derived Column transformation.
Can i get there from here, or must i recreate every stinking definition in a derived column manually from the ground up?
thanks very much for your help
Hi:
In the derived column transformation editor, I have a Derived column name called FileGroupID. I would like to pass in a value for this column from a variable that I have set earlier in the scope. Can someone let me know, how to write the expression that does that and where do I specifiy that expression. I am thinking its the expression field in the derived column transformation editor. My main question is how to actually write the expression, what is the syntax to pull the variable value? Thanks.
MA2005
I have a float of 70.83333333343
If I do this
SET @Output=ROUND(@Output, 2, 1) -- @Output is DECLARED as FLOAT
I get this:
70.82999999999999
I want:
70.83
How do I do that?
Thanks in advance...
In my maintenance plan task I have added a final step, an execute T-SQL statement, the code is simple, just a truncate of the database log to free space in the server, the code I am using is this on:
use NAV001
GO
DBCC SHRINKFILE(NAV001_Log, 1)
BACKUP LOG NAV001 WITH TRUNCATE_ONLY
DBCC SHRINKFILE(NAV001_Log, 1)
The problem is that I get an error when the maintenance task reach this step, the error log says that:
DBCC SHRINKFILE(NAVISION_PRUEBAS_Log, 1)" failed with the following error: "Could not locate file 'NAV001_Log' for database 'master' in sys.database_files. The file either does not exist, or was dropped.
Why is it trying to use master database if I am telling sql server to "use NAV001" in the first sentence?
Hi,
I have dates in "mmddyy" format coming from the sources and they are older dates of mid 80s like 082580 for instance.
When I cast it this way (DT_DBTIMESTAMP) Source_Date , It says ok but throws a runtime error.
When I hardcode a date in same format, (DT_DBTIMESTAMP) "082580" , It becomes red (an indication of syntax error) . Please note that we use double quotes in expressions in Derived Column Transformation; So an anticipation that using double quotes over single ones would be the syntax problem would be wrong.
Any help in this will sincerely be appreciated.
Thanks
Posted - 09/10/2007 : 15:53:26
Hey all - got a problem that seems like it would be simple (and probably is : )
I'm importing a csv file into a SQL 2005 table and would like to add 2 columns that exist in the table but not in the csv file. I need these 2 columns to contain the current month and year (columns are named CM and CY respectively). How do I go about adding this data to each row during the transformation? A derived column task? Script task? None of these seem to be able to do this for me.
Here's a portion of the transformation script I was using to accomplish this when we were using SQL 2000 DTS jobs:
'**********************************************************************
' Visual Basic Transformation Script
'************************************************************************
' Copy each source column to the destination column
Function Main()
DTSDestination("CM") = Month(Now)
DTSDestination("CY") = Year(Now)
DTSDestination("Comments") = DTSSource("Col031")
DTSDestination("Manufacturer") = DTSSource("Col030")
DTSDestination("Model") = DTSSource("Col029")
DTSDestination("Last Check-in Date") = DTSSource("Col028")
Main = DTSTransformStat_OK
End Function
***********************************************************
Hopefully this question isnt answered somewhere else, but I did a quick search and came up with nothing. I've actually tried to utilize the script component and the "Row" object, but the only properties I'm given with that are the ones from the source data.
thanks in advance!
jm
Can anyone show how to alter the value in a column using DerivedColumn component when creating an SSIS package programatically.
View 4 Replies View Related
Table structure as follows
Employee
Empno empname salary
commission
I want to have an other employee table named employee_modified
Empno empname salary
commission derived_column1(salary+commission)
derived_column2(derived_column1 + xxxx) and so on derive other
columns based on the earlier derived columns)
Is that possible to do it.. or am I doing something wrong.
something like
Select empno , empname , salary , commission,
(salary + commission) as derived_colum1 ,
(derived_colum1 + xxxxx) as derived_colum2 ,
(derived_colum2 + xxxxx) as derived_colum3
into employee_modified from employee
Hi,
for some reasons, I have to get access to the TaskHost during validation and execution. For example, I wanna know, if my task is within a container or not (parent is Sequence).
For the UI during design time, there is the TaskHost parameter. What about the execution time or during validation?
Any hints?
Thanks.
Thorsten
Hi, how are you?
I'm having a problem and I don't know if it can be solved with a derived column expression. This is the problem:
We are looking data in a a sql database.
We are writting the SQL result in a flat file.
We need to transform data in one of the columns.
For example: we can have 3 digits as value in a column but that column must be 10 digit length. So we have to complete all the missing digits with a zero. So, that column will have the original 3 digits and 7 zeros. How we can do that tranformation? We must do it from de the flat file or it can be a previous step?
Thanks for any help you can give me.
Regards,
Beli
Hi
We used to used Sql Server 2000 DTS to perform daily backups to remote servers very successfully but just cannot do the same with SSIS.
I set my Transfer Sql Transfer Objects Task to use the following settings:
CopyData = true
ObjectsTocopy = All Tables
As soon as it hits a table that has a foreign key, I get the following error:
"Truncate data failed for Table nnn"
I've tried setting DropObjectsFirst = True but this fails too with foreign key violations.
First of all, am I doing something obviously wrong? Is SSIS not smart enough to drop tables in the right order so that we don't get foreign key violations?
Am I totally barking up the wrong tree with this and can anyone suggest a better way of doing remote backups?
Kind regards
Ben
Hi,
I have a flat file(pipe delimited), like below( only two rows shown)
1|001|B|C|002|A|003|
1|005|D|C|003|A|004|
I have to import column 2( that is 001), column 5 (that is 002), column 7(that is 003) from the above flat file to column in Database that has DataType Numeric DataTyp (4,3).
In the Database the columns shoule have values like(.001), (.002), (.007). I have used flat file source, Script component, and OleDbDesitnation in my DataFlow task.
In the script component, I have added a "." for each column as a string.
I cannot import to OldeDbDestination becuase of Data conversion issue.
Is there any way we can solve this..
Thank you.
Code:
credit | debit | cash_in_hand
------------------------------
100 100 0
consider this as my table where i have an requirement where i need to truncate just the column cash_in_hand but if i do something like this
Code:
delete from credit_debit_table where cash_in_hand = '0'
then it will delete the entire row with credit & debit information but i need to delete only cash_in_hand column how to do that ?
note : i need to delete only data not the structure of cash_in_hand
I am trying to have an Excecute SQL Task return a single row result set executed on SQL Server 2005.
The query in the Execute SQL Task is:
select 735.234, 2454.123
I get a conversion error when trying to assign to SSIS variables of type Double.
I have nothing configured in the "Parameter Mapping" tab.
I have the two SSIS Double variables mapped to the Tesult Name 0 and 1 in the "Result Set" tab
I don't want to use a for loop enumerator since there is a single row returned.
I simply want to assign these two values to SSIS Double variables (double is the closest match)
I can't even hack this by converting the decimals as string and then using DirectCast to convert them to Double.
Thanks for the help
I recieve data where I am comparing zip codes from raw data, to a zip code table. The columns I am matching are in integers.
The issue is that in the raw data, sometimes the zip code is extended to more than the 5 characters in the zip code table so I am getting null value returns
A sample of this is in the raw data is:
Zipcode
54303
54304786
78641
Is there a way I can have it compare only the first 5 digits of the zip codes in the raw data zip code column to the zip code table? Or would I have to convert the data type? Or alter or truncate the characters somehow? If so, please include how to do this. Any help would be greatly appreciated. Thank you!
Hi, wondering if anyone can help me. I currently have a field that has a date and time in it in the format dd/mm/yyyy hh:mm:ss. Ideally I would like to get rid of the time part of it altogether but for it to still be recognised as a date as opposed to a string. However, I've been told that this is not possible in 2005, is this true? If this is the case, what would be the best way to set the time to 00:00:00 after the date for all records on that field?
View 1 Replies View RelatedI have two columns made up of 4 digits numbers eg col1 1234, col2 9876
I want to create a derived column so i get a eight digit column, eg col3 12349876
I cannot seem to get the expression right, I seem to be always adding the value which i do not want, can someone help me out with the expression
Thanks
Robbie
I am trying to transfer data from SQL Server 2005 table to another SQL Table. In the source table there is a field called Region [nvarchar(max)]. The values for these fields will be like APAC-China, NA-Racine, etc., i.e Region followed by the country name seperated by - symbol. I want the destination tablre with 2 fields Region[nvarchar(max)] and Country [nvarchar(max)]. I am using a Derived Column task to achieve the same.
Can anyone please help me out in doing this data conversion?
Thanks
Hi,
I am doing a task which will get all data based on several base and crosswork tables. I used stored procedure to get the data, but the next step will be using derived column to massaging data, and to load to the destination database. Is there a way to do that since I must generate data on the fly?
Thanks,
Megan
Hi Guys,
How can i put in a derived column the value of 3 columns? I've tried these:
[MyId]+[Paper1]
"[MyId]+[Paper1]"
but no luck. How can i put it right?
Thanks
Gemma
I am trying to create a derived column from two separate fields. One is a date field in format of 2008-03-01 and one is a time field. In DTS I use to have something like this:
DTSDestination("TransactionDate") = cdate(DTSSource("DSRHDATI")) & " " & timevalue(DTSSource("DSRHTIME"))
I am trying to figure out how to do this in SSIS. I know I have to use a dervived column but can't seem to come up with the correct syntax. Any help would be apprecaited. thanks.
Stacy
Can someone help me with the following query? I need to take the derived value from one column and calculate another column with it.
SELECT UserID,
((SELECT COUNT(*) FROM HPN_LeadMatches)+(SELECT COUNT(*) FROM HPN_Painters)) As Total,
(SELECT COUNT(*) FROM HPN_Leads) / Main.Total
FROM HPN_LeadMatches As Main
The error i'm getting says is unkown column 'total'. Is there another way to accomplish this?
Thanks!!
In a Derived Column data flow transformation, why can't I refer to a derived column (added in that same transformation) in the expression for another derived column? It seems I am forced to chain 2 DC data flows, just to do something as conceptually simple as:
a = x + y; b = a²
On a related note: Can I define a variable that is scoped to each row? Can I bind a variable in an expression to avoid creating a new row, e.g.
let a = x + y; a²
as the expression for new row b?
Hi everyone,
I have a quizzing application where users log in, answer questions, and are ranked relative to each other. For this final ranking, I calculate their score using this formula -
score = (correct Qs answered) * 150 / (total Qs answered) + (total Qs answered)
The SQL query that i use to get this info is -
Code:
SELECT TOP 50 username, (sum(correct) * 150 / count(1) + count(1)) AS score, count(1) as totalq
FROM questionsstats
GROUP BY username
ORDER BY score DESC
This works just fine.
However, on top of this I need to put an additional restriction that only users who have at least answered 20 questions be counted in. How can I do this? Adding a simple 'WHERE totalq > 20' does not work. I get the error "Invalid column name 'totalq'.".
Surely there must be a simple way to do this?
Thanks.
Two questions regarding Derived Columns in SSIS
1. In a if else expression if condition is false how do you keep the value of the source column eg: Name == "" ? "Unknown" : Name
Above will change all the non blank values to Name and not the actual value
in the Name Column eg. John
2. I have a column (unicode string)that stores date and time (The source is flat file) Is it possible to write expression to select the 1st day of month based on that date, and use this derived column as input to a table with a datetime field.