HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Replace column values?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
valuesreplacecolumn

Problem

I recently got into SSIS and haven't been able to find what I am trying to achieve anywhere on the web.

I am trying to take some rows as input, and then replace one specific column's value with something else, and then return the rows with modified columns as output.

The problem is that I don't know which task to use.

I'm limited by SQL Server 2008.

How do I get started?

Solution

The way I would do this is with a Derived Column Transformation. Take a look at this example (hitting the sample database, AdventureWorks2012):

As you can see on this screenshot, what I'm doing is taking the Name column from AdventureWorks2012.HumanResources.Department (this would work with your version of SQL Server/SSIS as well, I believe. Although you would know pretty quickly if it doesn't) and using a conditional statement for my Expression:

Name == "Sales" ? "New Sales Name" : Name


What that is, is a short-hand conditional statement. It takes the Boolean result of Name == "Sales". If that's true (i.e. the Name is "Sales") then return "New Sales Name", or whatever string you'd want to substitute. If that's false (the Name is not "Sales") then just return the Name as it originally was.

Code Snippets

Name == "Sales" ? "New Sales Name" : Name

Context

StackExchange Database Administrators Q#47980, answer score: 6

Revisions (0)

No revisions yet.